Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the default constructor really necessary for nhibernate to persist an object?

Tags:

nhibernate

for some reason I don't wanna let user to create an instance of the object, without sending a property to the constructor but as I know the object should have default constructor and so it would be possible to create an instance with out sending requierd property. is there any way to prevent this problem? and if yes does it have any side effect?

like image 684
Adrakadabra Avatar asked Dec 21 '22 13:12

Adrakadabra


1 Answers

Just use a protected default constructor:

public class Product
{
    protected Product() { }

    public Product(Category category)
    {
        this.Category = category;
    }
}
like image 200
Sunday Ironfoot Avatar answered Feb 23 '23 00:02

Sunday Ironfoot