How can I add properties to an association (relati

2019-09-02 17:15发布

问题:

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 way to represent this using Entity?

回答1:

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)