Reputation: 1277
When using Fluent NHinbernate How do I make a PK Read only I tried to make it internal on the setter but I get this:
----> NHibernate.InvalidProxyTypeException : The following types may not be used as proxies: Domain.Address: method set_AddressId should be 'public/protected virtual' or 'protected internal virtual'
my mapping looks like:
Id(x => x.AddressId).GeneratedBy.Identity();
any Idea how to do this?
Upvotes: 0
Views: 178
Reputation: 6278
You need to make all methods and properties virtual. Ex.
public virtual int AddressId {get; private set;}
It all depends on what your line of inheritance and such is. The reason for declaring it virtual is the same as mocking a class. NHibernate needs to be able to override all the properties for lazy loading.
Upvotes: 0
Reputation: 804
Your property AddressId should be made protected and virtual, eg:
public class MyClass
{
public virtual int AddressId { get; protected set;}
}
Upvotes: 1