Mapping Private Properties
Hello,
i am using Automapping and have some private properties i need mapped.
For an example I have a Member class which contains a Component of Type Password.
Password contains private properties called Hash and Salt. The Password Component properties should be mapped to columns using the Component name as a Prefix ("ComponentName" + "PropertyName" - in this case PasswordHash and PasswordSalt).
I am following the "Expression" example in this "guide" http://wiki.fluentnhibernate.org/Fluent_mapping_private_properties
To register the private mapping i do the following when creating the AutoPersistenceModel
.Override(m => m.Map(Password.PrivateMappingExpressions.Hash)) .Override(m => m.Map(Password.PrivateMappingExpressions.Salt))
The problem is that it maps to columns named Hash and Salt and not PasswodHash and PasswordSalt like it is supposed to according to my Convention.
How can i fix it ?
Is there a way to solve this without having to use Strings (etc. call Column() method on the Map(...)) ?
It would be nice if it was able to use my Conventions for the naming. Else i will have to "duplicate" all the logic in my Convetions for every property i decide to override.
Martin :)
Comments are currently closed for this discussion. You can start a new one.
2 Posted by Martin F on 11 Mar, 2010 11:03 PM
I guess for Convetions to be applied i need to somehow add the properties to be mapped instead of using Override ?
I found the FindMappablePrivateProperties property, but i have no clue of how to use it or if it can be used for the purpose ?
Support Staff 3 Posted by James Gregory on 12 Mar, 2010 09:25 AM
Component columns should get automatically prefixed with the component name; however, the fact that you're overriding individual members is probably breaking that behaviour.
Private members aren't really supported with the automapper. We have a
PrivateAutoPersistenceModel
which uses theFindMappablePrivateProperties
function, but it's very specific in it's purpose and isn't very flexible.It's not ideal, but you're better off exposing your private members through a read-only public property; either that, or don't use the automapping for this particular case.
This is something we're addressing for the next (non-bugfix) release.
4 Posted by Martin on 12 Mar, 2010 02:03 PM
Thanks for the answer James
Looking forward to the next release.
... and thanks for all the effort you put into this project. :)
Support Staff 5 Posted by James Gregory on 17 Mar, 2010 10:08 AM
You're welcome, thanks for helping us improve it.
I'm going to mark this discussion as resolved, as there's not really any further action I can take for the time being. Don't worry though, this issue is already on our roadmap for the next proper release.
James Gregory closed this discussion on 17 Mar, 2010 10:08 AM.
James Gregory re-opened this discussion on 30 Apr, 2010 08:47 AM
Support Staff 6 Posted by James Gregory on 30 Apr, 2010 08:47 AM
I've been making some changes with regard to private fields and automapping. They're not yet in master, but will be for the next release. If you want to check them out, there's a v1.1--automapping-strategy branch.
The changes are insofar undocumented, but if you take a look at the Examples.FirstAutomappedProject example, and specifically at the ExampleAutomappingConfiguration.cs you might be able to pick up the changes. Basically, if you were to override
ShouldMap(Member)
in theExampleAutomappingConfiguration
, that method gets called for every member including fields now, while before it was only called with properties; if you return true from that method, that member will be mapped.Support Staff 7 Posted by James Gregory on 16 May, 2010 05:45 PM
Master now has support for private fields.
James Gregory closed this discussion on 16 May, 2010 05:45 PM.