实体框架获取 ICollection来自映射器
使用Entity Framework 4.1尝试获取整数集合,
基本上我有一个名为Spec的实体,
public class Spec {
public int Id{get;set;}
public string Name {get;set;}
public ICollection<int> TypeIds {get;set;}
}
表Specs具有列id、名称等,我试图将TypeIds映射到具有列specId TypeId的表SpecTypes,但我不能找出它的映射
我一直在绑这样的东西
modelBuilder.Entity<Spec>().HasMany(r => r.TypesIds)
.WithMany()
.Map(m => m.ToTable("SpecTypes")
.MapLeftKey("SpecId")
.MapRightKey("TypeId"));
using Entity Framework 4.1 trying to get a collection of ints,
basically I have a Entity called Spec
public class Spec {
public int Id{get;set;}
public string Name {get;set;}
public ICollection<int> TypeIds {get;set;}
}
the table Specs has the Columns id, Name, etc and I'm trying to map TypeIds to table SpecTypes with column specId TypeId and I can't figure out the mappings for it
I have been tying something like this
modelBuilder.Entity<Spec>().HasMany(r => r.TypesIds)
.WithMany()
.Map(m => m.ToTable("SpecTypes")
.MapLeftKey("SpecId")
.MapRightKey("TypeId"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不能拥有原始值集合的导航属性。我认为您只需要创建一个包含 Id 属性的实体并拥有这些属性的集合。所以你或多或少会有这样的东西:
I don't think you can have a navigation property to a collection of primitive values. I think you just need to created an entity that contains Id property and have a collection of these. So you would have more or less something like this:
根据您的描述,您可能想要建立这样的一对多关系。您通常只需要使用模型构建器来解决一些在类定义中无法完成的复杂映射。
Based on what you describe, you probably want to do one-to-many relationship like this. You normally only need to use modelbuilder to solve some complicated mapping which you cannot do it in class definition.