开发者

How can I add properties to an association (relationship) using the Entity Framework

开发者 https://www.devze.com 2023-01-26 06:17 出处:网络
I am using Entity Framework 4. I have a many-to-many association (relationship) between two entities:

I am using Entity Framework 4. I have a many-to-many association (relationship) between two entities:

  • Account
  • Subscription

The relationship is therefore: AccountSubscription. So an account (over time) can have many subscriptions and, obviously, a particular Subscription type can be held by many Accounts at once.

I want to add properties to this relationship (e.g. StartDate, EndDate, PaymentStatus). I can't see a way in Entity to add properties to an Association table. What is the best开发者_如何学C way to represent this using Entity?


You cannot add properties to associations in EF. You must simply create a new Entity instead of an Association, in order to mimic an association with properties.

So you would have

Accounts (Entity) - [0..1 to Many]  - AccountSubscription (Entity) - [Many to 0..1] - Subscription (Entity) 
0

精彩评论

暂无评论...
验证码 换一张
取 消