问题描述
你好。
我有简单的收集课程颜色
I have simple class for collection Color
public class Color
{
public int Id {get; set;}
public string Name {get; set;}
}
和这样的用户:
public class User
{
public int Id {get; set; }
public string Name { get; set; }
public IList<Color> FavourColors {get; set; }
public IList<Color> HateColors {get; set; }
}
我正在使用Entity Framework 5 CTP。
谁能帮我映射这些实体?
I'm using Entity Framework 5 CTP.
Who can help me map this entities?
我只能在类User中映射一个属性,但我不明白我可以映射第二个集合。
I can map only one property in class User, but I don't understand how I can map second collection.
Thx提前。
推荐答案
这适用于此映射:
It's works with this mapping:
&NBSP; &NBSP; &NBSP; &NBSP; modelBuilder.Entity< User>()。HasMany(u => u。 FavourColors )。WithMany();
&NBSP; &NBSP; &NBSP; &NBSP; modelBuilder.Entity< User>()。HasMany(u => u。 HateColors )。WithMany();
但不能使用:
modelBuilder.Entity<User>().HasMany(u => u.FavourColors ).WithMany();
modelBuilder.Entity<User>().HasMany(u => u.HateColors).WithMany();
but don't work with that:
=> c.Users);
; &NBSP; &NBSP; &NBSP; &NBSP; modelBuilder.Entity< User>()。HasMany(u => u。 HateColors )。WithMany(c
=> c.Users);
modelBuilder.Entity<User>().HasMany(u => u.HateColors).WithMany(c => c.Users);
这篇关于一个实体中两个相同的多对多映射。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!