开发者

Convert inherited NHibernate-Object to another Objects which inherits from the same base

I have the fallowing NHibernate-Objects:

Person inherits from Contact Company inherits from Contact

There are three tables: Contact,开发者_如何学Go Person, Company. Each tables has an Column Id which is of type Guid.

Now, I am searching the easiest way to convert a Object of Person to an Object of Company. Concret the Record in Contact should remain and the Record in Person should be deleted and instead an new Record in Company should be created where I write some values in.


Create a constructor on Company that accepts a Person and maps the properties:

public Company(Person person)
{
    // map properties from person to company
}

Usage:

var company = new Company(person);
// set additional properties
session.Delete(person);
session.Save(company);
session.Flush();


i would suggest you look at nhibernates discriminator logic and see if that is what you want to probably use. let me know if that works out for you.. a little google should help.. feeling a little lazy in the night to sit and explain hw it works.

Thanks,

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜