[英]Fluent nHibernate and JoinSubClasses
I am not sure if this a problem with my Fluent configuration or some logic in my thinking. 我不确定这是否是我的Fluent配置问题或我的思维逻辑。
Basically I have a Person class from which I have two inherited classes, Author and Borrower (it's a library system). 基本上我有从我有两个继承的类,作者和借款人(这是一个图书馆系统)一个Person类。 The mapping I have is. 我的映射是。
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.Id, "id");
Map(x => x.Name, "name");
// Subclasses
AddPart(new AuthorMap());
AddPart(new BorrowerMap());
}
}
public class AuthorMap : JoinedSubClassPart<Author>
{
public AuthorMap() : base("person_id")
{
Map(x => x.Country, "country");
HasMany(x => x.Books).Cascade.All().WithKeyColumn("book_id");
}
}
public class BorrowerMap : JoinedSubClassPart<Borrower>
{
public BorrowerMap() : base("person_id")
{
Map(x => x.UserName, "user_name");
HasMany(x => x.Schedule).Cascade.SaveUpdate().WithKeyColumn("borrower_id");
}
}
Now if I run the HQL "FROM Author a ORDER BY a.Name" it will return a list of all Author and Borrower entities where I obviously just want a list of authors. 现在,如果我运行HQL“从a.Name编写作者的FROM作者”,它将返回所有Author和Borrower实体的列表,而我显然只需要一个作者列表。 Please feel free to set me straight on this. 请随时让我直接讲。
A few things to try: 可以尝试的几件事:
WithTableName("Author")
在每个子类映射中,使用WithTableName("Author")
设置表名称 person_id
the key column on each subclass table? person_id
是每个子类表上的键列吗? If not, change base("person_id")
to base("key column name")
如果不是, base("person_id")
更改为base("key column name")
For example, I just tested a very similar query with the following mappings: 例如,我刚刚使用以下映射测试了一个非常类似的查询:
public class DigitalFreeSubscriptionMap : JoinedSubClassPart<DigitalFreeSubscription>
{
public DigitalFreeSubscriptionMap()
: base("DigitalFreeSubscriptions")
{
WithTableName("DigitalFreeSubscriptions");
...
and 和
public class FreeSubscriptionMap : JoinedSubClassPart<FreeSubscription>
{
public FreeSubscriptionMap()
: base("FreeSubscriptions")
{
WithTableName("FreeSubscriptions");
...
Both are subclasses of Subscription
. 两者都是Subscription
子类。 In the database I tested on there are 1700 DigitalFreeSubscriptions while there are over a million FreeSubscripions (and other kinds of subscriptions). 在我测试过的数据库中,有1700个DigitalFreeSubscriptions,而有超过一百万个FreeSubscripions(以及其他类型的订阅)。 The HQL query " FROM DigitalFreeSubscripion
" returned 1700 results. HQL查询“ FROM DigitalFreeSubscripion
”返回了1700个结果。
Per request, the top of the SubscriptionMap: 根据请求,SubscriptionMap的顶部:
public class SubscriptionMap : AuditableClassMap<Subscription>
{
public SubscriptionMap()
{
WithTable("Subscriptions");
Id(x => x.Id, "Subscriptions");
AddPart(new FreeSubscriptionMap());
AddPart(new DigitalFreeSubscriptionMap());
// More sublass mappings and then the field mappings
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.