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