Is the default constructor for nhibernate necessary to save an object?

for some reason, I don’t want the user to instantiate the object without sending the property to the constructor but since I know that the object must have a default constructor, and therefore it would be possible to create an instance without sending the requierd property. is there any way to prevent this problem? and if so, is there any side effect?

+3
source share
2 answers

Just use the default protected constructor:

public class Product
{
    protected Product() { }

    public Product(Category category)
    {
        this.Category = category;
    }
}
+5
source

All Articles