I’m examin some mapping examples which uses mapping by code, and I have one simple question
If I have two properties which are mapped like this
Property(x => x.UserName, m =>
{
m.Length(50);
m.NotNullable(true);
});
Property(x => x.UpperUserName, m =>
{
m.Length(50);
m.NotNullable(true);
m.UniqueKey(“UniqueUpperUserName”);
m.Access(Accessor.Field);
});
What this m.Access(Accessor.Field); means?
And why it’s used on these second property UpperUserName and not in the first one?
Thanks.
It means that NHibernate won’t use the property itself when reading and writing values, but the underlying field.
You can read more on available access types in NHibernate documentation. Just scroll down to Access and Naming strategies tables.