实体框架 4 中的类型化关联
我有一个关于 MS Entity Framework 4 中关联的问题:是否可以输入多对多关联?
例如,想象一组人和一组项目。我现在想要模拟的是人们与不同项目的关联,根据他们在该项目中扮演的角色来分类。
这可以通过 EF4 实现吗?还是我必须手动建模?
I have a question regarding associations in MS Entity Framework 4: Is it possible to have typed many-to-many associations?
For example, imagine a set of people and a set of projects. What I would like to model now is the peoples association to the different projects, typed by the role they play in this project.
Is this possible with EF4, or do I have to model it by hand?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须手工对其进行建模。可以有一些继承的解决方法,但我不希望您的人在所有项目中始终扮演相同的角色,因此它可能不起作用。另一种方法是使用多个多对多关联,以便每个角色都有自己的关联。
通过手动建模,我的意思是将联结表公开为单独的实体,其中将包括对人员、项目和角色的引用。如果您在数据库中以这种方式定义了它,这将自动发生。
You must model it by hand. There can be some workaround with inheritance but I don't expect that your person always plays the same role in all projects so it would probably not work. Another way is using multiple many-to-many associations so that each role has its own association.
By model it by hand I meant exposing junction table as separate entity wich will include reference to person, project and role. This will happen automatically if you have it defined this way in database.