Mapping property using backing field with different type.
Hi,
It seems that using fluent nhibernate's current access strategy syntax breaks the mapping when using different types on the property and the backing field if the property has a non-supported type. However, it works fine using the Reveal.Member<Source, Return>() strategy, but that requires magic strings which I'm not very fond off.
The code I want to map looks like:
private IList<MyType> m_MyTypes;
public virtual MyList<MyType> MyTypes
{
get { return MyList.From(m_MyTypes); }
}
The mapping code I would want looks like:
HasMany(x => x.MyTypes)
.Access.PascalCaseField(Prefix.mUnderscore);
The mapping I am forced to use due to this bug looks like:
HasMany<MyType>(x => Reveal.Member<MyParentType, IList<MyType>>("m_MyTypes"));
Which not only introduces magic strings but also forces me to enter a lot of type parameters.
I've also tried using this code, which I could live with:
HasMany(x => x.MyTypes)
.Access.PascalCaseField(Prefix.mUnderscore)
.CollectionType<IList<MyType>>();
But it gives me this error:
Custom type does not implement UserCollectionType: System.Collections.Generic.IList`1[[MyType]].
Is this something you've already recognized(?) and if so, do you have any plans to fix it in a coming release? :)
Besides this small limitation Fluent NHibernate is truly awesome!
Best regards,
Niklas Källander
2 Posted by Niklas Källander on 28 Jul, 2010 11:51 AM
Hi again,
Seems that I was way wrong about this working ( thought I got it to work though ):
But even if I use it correctly e.g:
It does not work, it can't find the "property" named "m_MyTypes", however, the documentation for Reveal.Member says "Reveals a hidden property or field for use instead of expressions".
Best regards,
Niklas Källander
3 Posted by cremor on 29 Jul, 2010 06:19 AM
I don't know about your main problem, but for your workaround you need to specify field access:
4 Posted by Niklas Källander on 29 Jul, 2010 09:00 AM
Hi Cremor,
Thanks for the response, never thought of adding that myself since the documentation said the Revel.Member could handle fields as well ( thought it looked for both )! Thank you! :)
The main issue, however, is still not solved, but I managed to get rid of the magic strings by inheriting ClassMap<> adding more functionality to my maps that are based on my own conventions. :)
Best regards,
Niklas Källander