映射问题 [英] Mapping problem
问题描述
您好
我有以下情况:
在数据库中我有两个实体:Item和ItemFee
In the DB I have two entities: Item and ItemFee
我的班级模型如下所示:
物品有一个Price属性,其中包含费用集合。
My class model looks like this:
An Item has a Price property which has a collection of Fees.
public class Item
{
public int Id {get;组; }
公价格价格{get;组; }
}
public class Item
{
public int Id { get; set; }
public Price Price { get; set; }
}
公共类价格
{
公共ICollection<费用>费用{得到;组; }
}
public class Price
{
public ICollection<Fee> Fees { get; set; }
}
有没有办法将ItemFee映射到Price属性中的Fee集合?
Is there a way to map the ItemFee to the Fee collection in the Price property?
谢谢为了你的帮助!
推荐答案
这取决于你的ItemFee打算代表什么&NBSP;这听起来像物品和费用之间的多对多表,即:
It depends on what your ItemFee intends to represent. It sounds like a many-to-many table between an Item and a Fee, i.e:
物品:ID,其他一些列
费用:ID,一些其他列
ItemFee:ItemID,FeeID(无其他栏目)
Item: ID, some other columns
Fee: ID, some other columns
ItemFee: ItemID, FeeID (no other columns)
EF EDMX设计师将自动生成如下:
公共类项目
{
public int Id {get;组; }
公共ICollection<费用>费用{得到;组; }
}
The EF EDMX designer will automatically generate this as follows:
public class Item
{
public int Id { get; set; }
public ICollection<Fee> Fees { get; set; }
}
公共课费用
{
public int Id {get;组; }
公共ICollection<项目>物品 {get;组; }
}
$
物品有费用导航属性,费用有物品导航属性。 对这些集合进行更改会自动反映在ItemFee表中 - 没有ItemFee实体。
public class Fee
{
public int Id { get; set; }
public ICollection<Item> Items { get; set; }
}
Item has a Fees navigation property, and Fee has an Items navigation property. Making changes to these collections automatically get reflected in the ItemFee table - there is no ItemFee entity.
我认为缺少的是您在价格和费用之间定义关系的方式,这个关系在一个项目和费用之间的关系如何不同?
I think the piece that is missing is how your relationship is defined between a Price and a Fee, and how does this relationship differ between that of an Item and a Fee?
Joe
这篇关于映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!