如何使用实体框架向关联(关系)添加属性 [英] How can I add properties to an association (relationship) using the Entity Framework

查看:101
本文介绍了如何使用实体框架向关联(关系)添加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实体框架4.我有两个实体之间的多对多关联(关系):

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


  • 帐户

  • 订阅

因此,关系是:AccountSubscription。所以一个帐户(随着时间的推移)可以有很多订阅,显然,一个特定的订阅类型可以被许多帐户一次持有。

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.

我想为此关系添加属性(例如StartDate,EndDate,PaymentStatus)。我在Entity中看不到一种方式来向关联表添加属性。使用实体代表这种方式的最好方法是什么?

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?

推荐答案

您不能在EF中添加属性到关联。您必须简单地创建一个新的实体而不是关联,才能模拟与属性的关联。

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.

所以你会有

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

这篇关于如何使用实体框架向关联(关系)添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆