views:

22

answers:

2

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?

A: 

Your property AddressId should be made protected and virtual, eg:

public class MyClass
{
  public virtual int AddressId { get; protected set;}
}
Chris van de Steeg
A: 

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.

mhenrixon

related questions