Convert a legacy NHibernate-Object to another object that inherits from the same base

I have the following NHibernate-Objects:

Man inherits from contact Company inherits from Contact

There are three tables: Contact, Person, Company. Each table has a column identifier that is of type Guid.

Now I'm looking for the easiest way to convert a Person object to a company object. The specific record in the contact should remain, and the record in your personal account should be deleted, and instead, create a new record in the company where I write some values.

+3
source share
2 answers

Create a constructor in the company that accepts Person and displays the properties:

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

Using:

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

nhibernates , . , .. google .. , , .

,

-1

Source: https://habr.com/ru/post/1793393/


All Articles