views:

13

answers:

2

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:

BaseTable
---------
* 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

A: 

Hi Sebastian

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.

isuruceanu
A: 

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" );
    }
}
Sebastian Edelmeier

related questions