[英]Mapping extra properties in a lookup table and EF
I have the following many-to-many relationship set up in my db. 我在数据库中建立了以下多对多关系。
Mapped using Code-First EF; 使用Code-First EF映射; A Ticket
has an ICollection
of Branch
and vice versa. Ticket
具有Branch
的ICollection
,反之亦然。
This all works fine but now I need to make a significant change since the spec has been fleshed out. 一切正常,但由于规范已完善,现在我需要进行重大更改。
Originally a single Ticket
could be marked as IsRead
but that, as a concept, only really works when the Ticket
is allocated to a single branch. 最初,单个Ticket
可以标记为IsRead
但是从概念IsRead
,仅当将Ticket
分配给单个分支时,它才真正起作用。 What I need to do is say that a Ticket
has been read at each individual Branch
. 我需要做的是说已经在每个Branch
读取了一个Ticket
。
Now my first thought is that I should change the relational table BranchTickets
so that it has an Identity column and the IsRead
property thus creating a one-to-many relationship but I don't know then how to map the two foreign keys using the Code-First Api. 现在我的第一个想法是,我应该更改关系表BranchTickets
,使其具有Identity列和IsRead
属性,从而创建一对多关系,但是我不知道该如何使用Code映射两个外键-第一位Api。
Would this be the right approach, and if so how would I go about ensuring EF maps the tables appropriately? 这是正确的方法吗?如果是,我将如何确保EF正确映射表?
If a Ticket
can only be deemed read at Branch
level, then I would say all you need to do is remove the IsRead
property from Ticket
and move it to BranchTickets
. 如果只能将Ticket
视为在Branch
级别读取 ,那么我要说的就是从Ticket
删除IsRead
属性并将其移到BranchTickets
。
This means each individual ticket can be associated with multiple branches which can have different read states. 这意味着每个单独的票证可以与可以具有不同读取状态的多个分支关联。
how would I go about ensuring EF maps the tables appropriately 我将如何确保EF正确映射表
This is a change you would need to make at DB level, you can then update your EF model. 这是您需要在数据库级别进行的更改,然后可以更新EF模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.