Fluent nHibernate 映射问题
我有两张桌子,比如说商店和部门。
ShopTable
ShopId
ShopName
DepartmentTable
DepartmentId
ShopId
Name
Type
好的,现在我将 shoptable 映射到 Shop 类
public class Shop
{
public virtual int ShopId {get; set;}
public virtual string ShopName {get; set;}
public virtual Department Toys { get; set; }
public virtual Department Hardware { get; set; }
public virtual Department Food { get; set; }
}
public class Department
{
public virtual int DepartmentId { get; set; }
public virtual int ShopId { get; set; }
public virtual string Name { get; set; }
public virtual DepartmentType Type { get; set; }
}
如何映射玩具硬件和食物?
public class ShopMap : ClassMap<Shop>
{
Id(x => x.ShopId);
Map(x=> x.ShopName);
// How do I map these according to the DepartmentType enum?
Map(x=> x.Toys);
Map(x=> x.Hardware);
Map(x=> x.Food);
}
public class DepartmentMap : ClassMap<Department>
{
Id(x => x.DepartmentId);
Map(x=> x.ShopId);
Map(x=> x.Name);
Map(x=> x.Type);
}
I have two tables, lets say shop and department.
ShopTable
ShopId
ShopName
DepartmentTable
DepartmentId
ShopId
Name
Type
Ok now I map shoptable to Shop class
public class Shop
{
public virtual int ShopId {get; set;}
public virtual string ShopName {get; set;}
public virtual Department Toys { get; set; }
public virtual Department Hardware { get; set; }
public virtual Department Food { get; set; }
}
public class Department
{
public virtual int DepartmentId { get; set; }
public virtual int ShopId { get; set; }
public virtual string Name { get; set; }
public virtual DepartmentType Type { get; set; }
}
How do I map the toys hardware and food?
public class ShopMap : ClassMap<Shop>
{
Id(x => x.ShopId);
Map(x=> x.ShopName);
// How do I map these according to the DepartmentType enum?
Map(x=> x.Toys);
Map(x=> x.Hardware);
Map(x=> x.Food);
}
public class DepartmentMap : ClassMap<Department>
{
Id(x => x.DepartmentId);
Map(x=> x.ShopId);
Map(x=> x.Name);
Map(x=> x.Type);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定数据库表架构,您在问题中显示的类结构将不支持您想要执行的操作。 Shop 类与 Department 类之间存在一对多关系。以下是一个适用于您的表结构的映射:
对于以下映射:
The class structure you show in the question won't support what you want to do given the database table schema. There is a one-to-many relationship from the Shop class to the Department class. Here is a mapping that will work given your table structure:
For a mapping of: