开发者

Fluent NHibernate Hierarchical Data Question (One Table Per Hierarchy)

开发者 https://www.devze.com 2023-01-21 17:55 出处:网络
I am having some trouble depicting a DataBase Setup in NH. I have the following Classes: public class BaseData

I am having some trouble depicting a DataBase Setup in NH.

I have the following Classes:

    public class BaseData
    {
       public virtual long Id { get; set; }
    }

    public class ExtendedData : BaseData
    {
       public virtual string Name { get; set; }
    }

The backing tables look like the following:

Bas开发者_Python百科eTable
---------
* Id 

ExtendedTable
-------------
* Id
* Name

Use case : I create an ExtendedData instance that I want to persist. I expect entries in both tables (with the same Id from a sequence).

Does anybody have an idea how to create a fluent mapping for this?

Thanks a lot in advance!

Seb


As you have a base class you could ignore it on mapping. Use .IgnoreBase<>() method

example:

autoPersistenceModel.IgnoreBase<AdvanceEntity>().IgnoreBase<BaseAchievableArea>().IgnoreBase<AuditableEntity>();

Hope that this will direct you on right side.


Looking back, that was all too easy...

public class BaseDataMapping : ClassMap<BaseData>
{
    public BaseDataMapping()
    {
        this.LazyLoad();
        this.Table("BaseTable");
        this.Id(x => x.Id, "id").GeneratedBy.Native("SEQ_ID");         
    }
}

public class ExtendedDataMapping : SubclassMap<ExtendedData>
{
    public ExtendedDataMapping()
    {
        this.LazyLoad();
        this.Table( "ExtendedTable" );
        this.Map(x=>x.Name, "Name" );
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号