You map classes in NHibernate, not with interfaces. As others have pointed out, you mislead the readonly keyword using a read-only property: the readonly keyword means that the field can only be set in the constructor. The read-only property does not have either a private setter.
But I think you can achieve what you want using this:
public interface IEntity { string Name { get; } } public class Entity : IEntity { public string Name { get; private set; } } public class EntityMap : ClassMap<Entity> { public EntityMap() { Map(x => x.Name); } }
NHibernate uses reflection, so it can set the Name property, but it is read-only in your application.
source share