C# Fluent-nHibernate和joinsubclass
我不确定这是我流畅的配置问题还是我思维中的逻辑问题 基本上我有一个Person类,从中我继承了两个类,Author和follower(这是一个库系统)。我拥有的映射是C# Fluent-nHibernate和joinsubclass,c#,.net,nhibernate,fluent-nhibernate,C#,.net,Nhibernate,Fluent Nhibernate,我不确定这是我流畅的配置问题还是我思维中的逻辑问题 基本上我有一个Person类,从中我继承了两个类,Author和follower(这是一个库系统)。我拥有的映射是 public class PersonMap : ClassMap<Person> { public PersonMap() { Id(x => x.Id, "id"); Map(x => x.Name, "name"); // Subcla
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");
}
}
公共类PersonMap:ClassMap
{
公众人物地图()
{
Id(x=>x.Id,“Id”);
映射(x=>x.Name,“Name”);
//子类
AddPart(新的AuthorMap());
AddPart(新的借用映射());
}
}
公共类AuthorMap:JoinedSubclass部分
{
public AuthorMap():base(“person\u id”)
{
地图(x=>x.国家,“国家”);
HasMany(x=>x.Books).Cascade.All().WithKeyColumn(“book_id”);
}
}
公共类借用映射:JoinedSubclass部分
{
公共借阅者映射():基本(“个人id”)
{
映射(x=>x.UserName,“用户名”);
HasMany(x=>x.Schedule).Cascade.SaveUpdate().WithKeyColumn(“借款人id”);
}
}
现在,如果我运行HQL“FROM Author a ORDER BY a.Name”,它将返回所有作者和借用者实体的列表,我显然只需要一个作者列表。请随时告诉我这一点。有几件事可以尝试:
- 在每个子类映射中,使用
WithTableName(“作者”)
是每个子类表上的键列吗?如果没有,请将person\u id
更改为base(“个人id”)
base(“关键列名”)
public class DigitalFreeSubscriptionMap : JoinedSubClassPart<DigitalFreeSubscription>
{
public DigitalFreeSubscriptionMap()
: base("DigitalFreeSubscriptions")
{
WithTableName("DigitalFreeSubscriptions");
...
public class FreeSubscriptionMap : JoinedSubClassPart<FreeSubscription>
{
public FreeSubscriptionMap()
: base("FreeSubscriptions")
{
WithTableName("FreeSubscriptions");
...
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