Conventions?  Over configuration?  Really?  Who'd want to do
that?   ;)

So I'm disappointed as there appears to be a bug in the conventions.
I tried creating a couple like so:

new PropertyConventionBuilder().Always(x =>
x.Access.CamelCaseField(CamelCasePrefix.Underscore));
new CollectionConventionBuilder().Always(x =>
x.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore));

But there appears to be a flaw in the way the conventions are
applied.  I created a "Customer" class with a couple of properties
like this:

        public virtual IEnumerable<Order> Orders
        {
            get { return _orders; }
        }

        public virtual string Name
        {
            get { return _name; }
        }

and my conventions were not applied.  Just for testing purposes (I
don't recommend actually doing this in real code!) I tried the
following and then the conventions worked:

        public virtual IEnumerable<Order> Orders
        {
            get { return _orders; }
            private set { }
        }

        public virtual string Name
        {
            get { return _name; }
            private set { }
        }

I think that for some reason that the automapper is applying the
convention incorrectly by checking the reflected property descriptor
to see if it is "settable".  But since I'm using a field behind my
property, this check should not occur.

Of course the Overrides still work such as:

.Override<Order>(map => map.Map(x =>
x.Number).Access.CamelCaseField(Prefix.Underscore))

but I completely understand your desire to do this with conventions.
Otherwise you'll have a lot of manual mapping, which defeats a lot of
the purpose of the automapper.

Feedback from project contributors/committers is greatly appreciated!

--Jeff






On Apr 18, 9:26 am, m4bwav <[email protected]> wrote:
> Thanks for responding, I do this currently in an override oriented
> class, the problem is, I do this a lot.
> This strategy kind of neutralizes half the power of the automapper by
> forcing me to hand define many public/private pairs.
>
> I just wish that fluent nhibernate would expose some sort of
> convention type that I could subclass into allowing me to do this to
> all properties that fit certain criteria.
> But months ago I tried to force the automapper to auto-dynamically map
> to readonly backing fields, I failed because it appeared impossible.
>
> Am I totally off my rocker here? :)
>
> Thanks for any information
> Mark Rogers
>
> On Apr 13, 2:20 pm, Jeff Doolittle <[email protected]> wrote:
>
>
>
> > It works if you expose a public getter property that has a private
> > backing field.
>
> > Assuming an entity type
>
> > "Order"
> > with public property "public int Total { { return _total; } }"
> > with  backing field "private int _total;"
>
> > You can do this:
>
> > AutoPersistenceModel.Override<Order>(map => map.References(x =>
> > x.Total).Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore))
>
> > --Jeff
>
> > On Apr 12, 8:51 am, m4bwav <[email protected]> wrote:
>
> > > Found the answer, there is no direct support for readonly backing
> > > fields in the fluent nhibernate auto-mapper.
>
> > > On Apr 12, 12:00 am, m4bwav <[email protected]> wrote:
>
> > > > I posted this question on stack 
> > > > overflow:http://stackoverflow.com/questions/2619954/can-fluent-nhibernates-aut...
>
> > > > On Apr 11, 11:33 am, m4bwav <[email protected]> wrote:
>
> > > > > Oh nevermind support forum is not functioning until the April 16th.
> > > > > So I will see if I can game an answer here.
>
> > > > > Not my bad,
> > > > > Mark
>
> > > > > On Apr 11, 11:31 am, m4bwav <[email protected]> wrote:
>
> > > > > > Sorry I just read the message about the support forum, I'll repost 
> > > > > > the
> > > > > > question there.
>
> > > > > > My Bad,
> > > > > > Mark
>
> > > > > > On Apr 11, 11:28 am, m4bwav <[email protected]> wrote:
>
> > > > > > > Hey, love Fluent nhibernate, thanks for the work, quick question.
>
> > > > > > >   I like private readonly backing fields because some objects are
> > > > > > > mostly read-only after creation, and for collections, which should
> > > > > > > almost never be set wholesale (seems like, since there are add and
> > > > > > > remove item methods).  But as far as I remember 
> > > > > > > fluent-nhibernate's
> > > > > > > automapper never had a solution for private readonly backing 
> > > > > > > fields,
> > > > > > > I'm wondering if that's changed in the last few months. So here's 
> > > > > > > my
> > > > > > > question:
>
> > > > > > > How do I configure automapper or create an automapping convention 
> > > > > > > to
> > > > > > > map private readonly backing fields?
>
> > > > > > > Thanks,
> > > > > > > Mark
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Fluent NHibernate" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/fluent-nhibernate?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to