Following Fabio's suggestion you could create custom property accessor
based on FieldAccessor:
public class GetterOnlyPropertyAccessor : FieldAccessor
{
public GetterOnlyPropertyAccessor() : base(new BackFieldStrategy())
{}
}
and use it:
Property(e => e.Name, pm =>
{
pm.Column("Name");
pm.Access(typeof(GetterOnlyPropertyAccessor));
});
Ideally nhibernate-core should be changed to support BackFieldStrategy by
default for ByCode Accessor.NoSetter and Accessor.Field modes.
https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate/Mapping/ByCode/PropertyToField.cs#L10
On Tuesday, October 13, 2015 at 1:21:06 AM UTC+10, sturdytree wrote:
>
> Hi Fabio, does your post imply we can map the new getter only auto
> properties? Would you mind showing how?
>
> On Monday, October 12, 2015 at 1:52:10 PM UTC+1, Fabio Maulo wrote:
>>
>> FiledAccessor with BackingField strategy
>>
>> https://github.com/nhibernate/nhibernate-core/blob/f5b97a84dbcd19a8604111318f6697ae44162902/src/NHibernate/Properties/BackFieldStrategy.cs
>>
>> On Saturday, September 26, 2015 at 9:17:32 AM UTC-3, sturdytree wrote:
>>>
>>> In C# 6.0 we can now write:
>>>
>>> public string Name {get;}
>>>
>>> instead of
>>>
>>> public string Name {get;private set;}
>>>
>>> or using a private backing field.
>>>
>>> Whereas the mapping worked for the old code, the new code now gives a
>>> 'could not find a setter' exception.
>>>
>>> Is there a way to get NHibernate to work with getter only auto
>>> properties?
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.