I have the following class which I am mapping using Fluent NHibernate's AutoMapper. I do not want the list items publically modifiable so have a public IEnumerable
backed by an IList
which can be populated internally or by NHibernate.
I want NHibernate to map teamMembers
to a column named TeamMembers
. I also want FNH to ignore the TeamMembers
property on this class.
public class Team : Entity
{
protected internal virtual IList<Person> teamMembers { get; set; }
public IEnumerable<Person> TeamMembers { get { return teamMembers;} }
}
Here's how you tell NHibernate's Autopersistence model to ignore your property:
var cfg = Fluently.Configure()
.Database(configurer)
.Mappings(m =>
{
m.AutoMappings.Add(AutoMap.Assemblies(Assembly.GetExecutingAssembly())
.Override<Team>(map => map.IgnoreProperty(team => team.TeamMembers)));
});
You would then have just what you want.