Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Fluent-nHibernate和joinsubclass_C#_.net_Nhibernate_Fluent Nhibernate - Fatal编程技术网

C# Fluent-nHibernate和joinsubclass

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

我不确定这是我流畅的配置问题还是我思维中的逻辑问题

基本上我有一个Person类,从中我继承了两个类,Author和follower(这是一个库系统)。我拥有的映射是

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