I'm trying to complete some first step with fluent nhibernate with sql server express, to add this features in my project. But got some errors. As I'm newbie to nhibernate, couldn't solve a problem for some time. I have an entity with
Id { get; private set; }
accessors. And this entity is mapped to table with identity {1,1} column in sql server. But during creating Session factory, I get an error:
The following types may not be used as proxies:Entity: method set_Id should be 'public/protected virtual' or 'protected internal virtual'
I understand that private setter is used to encapsulate setting of this property, but why do I get this error then? PS: example on site of fluent for nhibernate is using sqllite db and everything is just fine.
This is an issue that has caused grief for many NH/FNH users, including me.
Until recently, NHibernate has allowed private setters with proxy objects. But starting with NH 3.2, private setters are no longer allowed - they must be "'public/protected virtual' or 'protected internal virtual'", as the error message says.
This is a breaking change for a lot of the FNH/NH sample code that's out there, and is especially confusing to newbies.
Declare the property as public virtual int Id { get; protected set; }
. The proxy object generated by NHibernate will then be able to set the property.
Another solution can be to use a backing field:
private int id;
public int Id
{
get { return id; }
}
And then use mapping:
Map(x => x.Id).Access.CamelCaseField();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With