FluentNhibernate,将类映射到多个表
考虑类 A、B 和 C,A 和 B 都有 C 的集合。我想将这些集合映射到不同的表,所以我有表 A_C 和 B_C。我尝试这样做:
public class AMap : ClassMap<A>
{
Public AMap()
{
Id(x => x.Id).GeneratedBy.Identity();
HasMany(x => x.Cs).Table("A_C");
}
}
public class BMap : ClassMap<B>
{
Public BMap()
{
Id(x => x.Id).GeneratedBy.Identity();
HasMany(x => x.Cs).Table("B_C");
}
}
public class CMap : ClassMap<C>
{
Public CMap()
{
Id(x => x.Id).GeneratedBy.Identity();
}
}
..(具有一些额外的属性),但它仍然只创建一个名为“C”的表。那么正确的方法是什么呢?
Consider class A, B and C, both A and B has a collection of Cs. I want to map these collections to different tables, so I have table A_C and B_C. I try to do:
public class AMap : ClassMap<A>
{
Public AMap()
{
Id(x => x.Id).GeneratedBy.Identity();
HasMany(x => x.Cs).Table("A_C");
}
}
public class BMap : ClassMap<B>
{
Public BMap()
{
Id(x => x.Id).GeneratedBy.Identity();
HasMany(x => x.Cs).Table("B_C");
}
}
public class CMap : ClassMap<C>
{
Public CMap()
{
Id(x => x.Id).GeneratedBy.Identity();
}
}
..(with some extra properties), but it still creates just a single table of name "C". So what is the correct way to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说,继续制作单独的表(自行创建,而不使用模式导出)并按照您知道它们应该工作的方式正确配置映射。只要您配置正确,NHibernate 就应该解决问题。您可能必须告诉它要加入的键列的名称。您仍然可以使用架构导出来生成其他表。完成后,转到 NHibernate 后面并添加额外的表。
NHibernate 应该正确地进行连接。如果没有,请告诉我。另外,如果您正在处理复合键并需要帮助,请告诉我。
I'd say go ahead and make your separate tables (on your own without using schema export) and properly configure your mappings the way you know they should work. NHibernate should figure things out so long as you've configured things correctly. You might have to tell it the name of the key column to join on. You can still use schema export to generate the other tables. After it's finished, go behind NHibernate and add your extra table.
NHibernate should do the joins properly. Let me know if it doesn't. Also, if you're dealing with a composite key and need help with that, let me know.