leora
leora

Reputation: 196589

How to convert a child class into a parent class for saving in NHibernate?

I have the following classes called:

public class Parent
{
     public string Field1;
     public string Field2; 
}

public class Child : Parent
{
    public string Field3;
}

I now have a list of Child objects and I need to pass then into a function that is looking for a Parent class.

What is the best way to convert Child class back to the Parent class (I don't care about field3 at this point)?

I am using NHibernate and when I pass in the child class and try to save it, I get this error:

No persister for: ChildClass

even though the 'Parent' class has a persister.

Upvotes: 0

Views: 289

Answers (1)

SLaks
SLaks

Reputation: 887509

Instances of the child class are instances of the parent class.
You don't need to do anything special.

Upvotes: 9

Related Questions