在代码优先EF4许多一对多的关系 [英] Many-To-Many Relationship in Code-First EF4
问题描述
您代表了EF4代码优先CTP3一个多一对多的关系怎么办
How do you represent a many-to-many relationship in the EF4 Code-First CTP3?
例如,如果我有以下类:
For example if I have the following classes:
class User
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Profile> Profiles { get; set; }
}
class Profile
{
public int Id { get; set; }
public string Name { get; set; }
}
在数据库中存在着具有FK为用户一个的UserProfiles表和FK的个人资料。我该如何映射这个
In the database there is a UserProfiles table that has the FK for User and FK for Profile. How can I map this?
编辑:我知道如何到目前具有映射的ICollection<使用者>
在配置文件属性
,但我真的不希望有一个相对的导航属性时,它应该是用户有很多的配置文件。
I understand how to to currently map with having a ICollection<User>
property on the Profile
, but I really don't want to have a an opposite navigation property when it should be "Users have many profiles".
推荐答案
修改:CTP4发布昨日晚间(2010年7月14日),而且现在支持这样的:
EDIT: CTP4 was released late yesterday (July 14 2010) and there is now support for this:
modelBuilder.Entity<邮政>()的hasMany(p => p.Tags).WithMany();
我发现的最后的,这目前是不可能的。微软正在添加此功能(只有一个导航属性)
I found out finally that this currently isn't possible. Microsoft is looking to add this feature (only one navigation property).
更多信息请参阅在MSDN论坛此链接: http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/6920db2b-88c7- 4BEA-ac89-4809882cff8f
See this link on the MSDN forums for more information: http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/6920db2b-88c7-4bea-ac89-4809882cff8f
这篇关于在代码优先EF4许多一对多的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!