Berryl,

Currently I have very few mapping overrides and they only really deal with edge 
cases such as sets of components that currently are not handled by automapping.
Almost everything is dealt with through the convention interfaces.
Although you have more classes it is so much easier to work with when you have 
clearly defined conventions with descriptive names.


-----Original Message-----
From: fluent-nhibernate@googlegroups.com 
[mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Berryl Hesh
Sent: 16 April 2009 19:40
To: Fluent NHibernate
Subject: [fluent-nhib] Re: conventions & overrides


I hear you. Maintenance is my goal too so even though it seems more
maintainable to me in one spot for now, I appreciate the benefit of
your experience here.

Are you finding your mapping override classes are doing less and less
as you use convention interfaces more? Anything at all?

On Apr 16, 9:40 am, "Martin Hornagold"
<martin.hornag...@marstangroup.com> wrote:
> The trouble with burying logic like that in the apply methods is that it 
> makes it less maintainable.
> In the case of your Email string length this is clearly a new different 
> convention.
> By having separate convention classes it makes that statement explicitly and 
> easier to see what is going on.
>
> -----Original Message-----
> From: fluent-nhibernate@googlegroups.com 
> [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Berryl Hesh
> Sent: 16 April 2009 17:10
> To: Fluent NHibernate
> Subject: [fluent-nhib] Re: conventions & overrides
>
> I think I like it better having one convention for like items (ie,
> string lengths), like this:
>
> public void Apply(IProperty property) {
>             if (property.Property.Name == "Email") {
>                 property.WithLengthOf(30);
>                 return;
>             }
>             property.WithLengthOf(50);
>         }
>
> No point in repeating this in the useless override. I'm sure there is
> a great reason why FNH does it this way but it seems more intuitive to
> me right now to have overrides go last.
>
> I guess the rule is that an override only makes sense where it is
> touching on something totally you can't figure out how to address by
> convention?
>
> On Apr 16, 8:44 am, "Martin Hornagold"
> <martin.hornag...@marstangroup.com> wrote:
> > Berryl,
>
> > The best way I have found is to create a separate property convention
> > for the edge case.
> > In this property convention create a static Accepts method to allow
> > cleaner calling of it from the default convention:
>
> > public class EmailStringLengthConvention : IPropertyConvention
> > {
> >         public bool Accept(IProperty property)
> >         {
> >                 return property.Name.Contains("Email");
> >         }
>
> >         public bool Apply(IProperty property)
> >         {
> >                 property.WithLengthOf(30);
> >         }
>
> >         public static Accept(IProperty property)
> >         {
> >                 return (new
> > EmailStringLengthConvention).Accept(property);
> >         }
>
> > }
>
> > Then the accept of your Default convention would accept anything not
> > accepted by the email convention
>
> > public class DefaultStringLengthConvention: IPropertyConvention
> > {
> >         public bool Accept(IProperty property)
> >         {
> >                 return !EmailStringLengthConvention.Accept(property);
> >         }
>
> >         public bool Apply(IProperty property)
> >         {
> >                 property.WithLengthOf(50);
> >         }
>
> > }      
> > -----Original Message-----
> > From: fluent-nhibernate@googlegroups.com
>
> > [mailto:fluent-nhibern...@googlegroups.com] On Behalf Of Berryl Hesh
> > Sent: 16 April 2009 16:22
> > To: Fluent NHibernate
> > Subject: [fluent-nhib] conventions & overrides
>
> > Please forgive me if the answer to this should be obvious from the
> > docs.
>
> > I'm using AutoMapping w/ conventions, and I have an override class.
> > The case I'm asking about happens to be re: StringLength but I'm
> > hoping the idea should be applicable to any convention.
>
> > Convention class
> > ------------------------
> > public class DefaultStringLengthConvention: IPropertyConvention
> >     {
> >         public bool Accept(IProperty property) { return true; }
>
> >         public void Apply(IProperty property) { property.WithLengthOf
> > (50); }
> >     }
>
> > Override
> > -----------------
> >         public void Override(AutoMap<User> mapping) {
> >             mapping.Map(x => x.Email).WithLengthOf(30);
> >         }
>
> > FNH looks at the override class before the convention, which explains
> > why the generated ddl for Email.StringLength winds up being 50 instead
> > of 30; so I'm guessing I need some logic in Accept() to deal with
> > this.
>
> > Is that the case?
>
> > Thx!
> > Berryl


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

Reply via email to