jquery auth
jquery auth

Reputation: 1277

How do I make a Primary Key read-only in Fluent NHibernate?

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

Answers (2)

mhenrixon
mhenrixon

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

Chris van de Steeg
Chris van de Steeg

Reputation: 804

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

public class MyClass
{
  public virtual int AddressId { get; protected set;}
}

Upvotes: 1

Related Questions