开发者

Subclass to map additional column of table

开发者 https://www.devze.com 2023-04-12 20:08 出处:网络
I have entity class A and Fluent NHibernate map for it AMap which maps some columns from database table (a few fields are missing). 开发者_开发技巧I would like to create class B which inherits from A

I have entity class A and Fluent NHibernate map for it AMap which maps some columns from database table (a few fields are missing). 开发者_开发技巧I would like to create class B which inherits from A (to not break relations with other entities) and map for it to allow access to columns not mapped by base class. The problem is that I cannot change any line of code in base classes (A and AMap). Is there any solution for this problem?


im not sure how you wanna use it but this could do

class B : A
{

}

class BMap : ClassMap<B>
{
    public BMap()
    {
        Table("A's tablename");
        ...
    }
}

then this should be possible

someEntity.ListOfAs.Add(new B());

dont know if there are problems down the road though


As far as I understand the requirement, this is a simple table per class hierarchy mapping. You'll need a discriminator column for that.

For the mapping see the last example on that page: Fluent Wiki.

0

精彩评论

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