James

Couple of things:

EmumerationTypeConvention.cs line 19 "propertyMapping.CustomSqlTypeIs
("string");"

AFAIK "string" is not a database type. I suspect you want to use the
dialect
thing here to write the correct type into the mapping.

The "string" thing just broke when I tried to run it against my DB.

Also although I now have:

convention.AddTypeConvention(new MyEnumToIntConvention());

in my auto mapping configuration my "AlterMap" method is never called
for my enum types.

I can see that the "FindConvetions" method in Conventions.cs line 80
does return my custom convention but the AlterMap part is never
called.

Not 100% sure if this whole enum thing is supported in the auto mapper
but thought I would being it up.

Thanks, Mark




On Feb 18, 4:14 pm, Mark Perry <markperr...@googlemail.com> wrote:
> Thing is how big do you make your "string" column in your DB to cater
> for all the lengths of the enums.
>
> The automapper is going to default to X but then some developer
> comes along and adds "thisisareallylingenumvalue" and all of the
> sudden
> that's going break on the inside of the DB and make the enum cast as
> the
> default instead of the really long one. That is bad.
>
> If I use Ints in my DB not only am I safe from magic strings but I get
> better indexing and reporting performance (yes I understand it's
> marginal)
> unfortunately that's how I grew up DB wise and my preferred solution.
>
> I realise that's more of a basic Nhibernate functionality question
> rather than a FNH one, thanks for the swift response though.
>
> In your opinion am I better overloading ToString for my enum types to
> return the Int value or creating an "AddTypeConvention" to handle it
> there?
>
> Thanks, Mark
>
> On Feb 18, 1:33 pm, James Gregory <jagregory....@gmail.com> wrote:
>
> > CustomTypeIs is for specifying IUserTypes, so no that wouldn't work.
> > Although perhaps I should remove that limitation and make CustomTypeIs just
> > be for any type.
>
> > On Wed, Feb 18, 2009 at 1:27 PM, blindwillie <asgerhal...@gmail.com> wrote:
>
> > > Shouldn't it be possible to do it like this:
>
> > > Map(x => x.MyEnum).CustomTypeIs(typeof(int));
>
> > > Because such line seems to be ignored right now. I don't know if
> > > removing the "highlighted" line in the automapper will change that?
>
> > > /Asger
>
> > > On Feb 18, 2:23 pm, James Gregory <jagregory....@gmail.com> wrote:
> > > > Well, that line you highlighted in AutoMapper doesn't make any sense.
> > > > Removing it allows the automapper to map Enums; however, the recommended
> > > > behavior in NHibernate is to map enums as strings, and that's what the
> > > > automapper does.
> > > > If you really must use enums as ints, then you'll need to manually set
> > > the
> > > > type attribute on the property. I've updated the enum convention to
> > > ignore
> > > > any enum properties that already have their type set.
>
> > > > Map(x => x.MyEnum)
> > > >   .SetAttribute("type", "Int32");
>
> > > > On Wed, Feb 18, 2009 at 9:17 AM, Mark Perry <markperr...@googlemail.com
> > > >wrote:
>
> > > > > James
>
> > > > > Have you had any ideas on this one yet?
>
> > > > > Mark
>
> > > > > On Feb 13, 3:07 pm, Mark Perry <markperr...@googlemail.com> wrote:
> > > > > > James
>
> > > > > > Is there anything I can do to help you out further?
>
> > > > > > Mark
>
> > > > > > On Feb 12, 5:51 pm, James Gregory <jagregory....@gmail.com> wrote:
>
> > > > > > > I'm not sure why those checks are in there, but I'll investigate
> > > when I
> > > > > next
> > > > > > > get an opportunity.
>
> > > > > > > On Thu, Feb 12, 2009 at 4:01 PM, Mark Perry <
> > > > > markperr...@googlemail.com>wrote:
>
> > > > > > > > Here as well in AutoMapComponent.cs
>
> > > > > > > > Line 35
>
> > > > > > > > if (property.PropertyType.IsEnum || property.GetIndexParameters
> > > > > > > > ().Length != 0) continue;
>
> > > > > > > > After taking both of the checks for
> > > "property.PropertyType.IsEnum"
> > > > > > > > from the source code and
> > > > > > > > running the auto mapper I get the XML outputting correctly.
>
> > > > > > > > <property name="DisplayAs" column="DisplayAs"
> > > > > > > > type="FluentNHibernate.Mapping.GenericEnumMapper`1
> > > > > > > > [[Engineering.Domain.DisplayAs, Engineering.Domain,
> > > Version=1.0.0.0,
> > > > > > > > Culture=neutral, PublicKeyToken=null]], FluentNHibernate,
> > > > > > > > Version=0.1.0.0, Culture=neutral,
> > > PublicKeyToken=8aa435e3cb308880">
> > > > > > > > <column name="DisplayAs" sql-type="string" />
> > > > > > > > </property>
>
> > > > > > > > I guess internally it's using the EnumerationTypeConvention() to
> > > do
> > > > > > > > the business. Unfortunately I cannot get the automapper to break
> > > into
> > > > > > > > my ITypeConvention for my Enum.
>
> > > > > > > > Also the default is to store as a string in the DB and not an 
> > > > > > > > Int
> > > > > > > > which it what I would like.
>
> > > > > > > > Dunno if any of this helps at all.
>
> > > > > > > > Thanks, Mark
>
> > > > > > > > On Feb 12, 3:19 pm, Mark Perry <markperr...@googlemail.com>
> > > wrote:
> > > > > > > > > Seems like the AutoMapper will always ignore Enums from the
> > > > > generated
> > > > > > > > > maps:
>
> > > > > > > > > AutoMapper.cs line 57
>
> > > > > > > > > if (!property.PropertyType.IsEnum &&
> > > property.GetIndexParameters
> > > > > > > > > ().Length == 0)
>
> > > > > > > > > Am I right here or should I be doing something else?
>
> > > > > > > > > Mark
>
> > > > > > > > > On Feb 12, 3:02 pm, Mark Perry <markperr...@googlemail.com>
> > > wrote:
>
> > > > > > > > > > @Steve
>
> > > > > > > > > > Yeah I get the state thing but all I want is a simple Enum 
> > > > > > > > > > to
> > > DB
> > > > > int
> > > > > > > > > > mechanism.
> > > > > > > > > > From my previous post I don't think this is currently 
> > > > > > > > > > working
> > > in
> > > > > the
> > > > > > > > > > AutoMapper.
>
> > > > > > > > > > Thanks, Mark
>
> > > > > > > > > > On Feb 12, 2:50 pm, Steven Harman <stevehar...@gmail.com>
> > > wrote:
>
> > > > > > > > > > > Mark,
> > > > > > > > > > > I like Derick Bailey's approach to solving this - Mapping 
> > > > > > > > > > > a
> > > > > State
> > > > > > > > Pattern
> > > > > > > > > > > with NHibernate:
>
> > > > >http://www.lostechies.com/blogs/derickbailey/archive/2008/11/26/mappi.
> > > ..
>
> > > > > > > > > > > -steve
>
> > > > > > > > > > > //----  90% of being smart is knowing what you're dumb at
> > > > >  ----//
> > > > > > > >http://stevenharman.net/
>
> > > > > > > > > > > On Thu, Feb 12, 2009 at 9:12 AM, Mark Perry <
> > > > > > > > markperr...@googlemail.com>wrote:
>
> > > > > > > > > > > > Hi
>
> > > > > > > > > > > > Sorry to keep pestering the list like this I feel like
> > > I'm
> > > > > being a
> > > > > > > > > > > > right pain in the [insert word here].
>
> > > > > > > > > > > > I wanted to have to AutoMapper map one of my properties
> > > which
> > > > > is an
> > > > > > > > > > > > Enum but it seems as
> > > > > > > > > > > > if the AutoMapper just ignores it.
>
> > > > > > > > > > > > I know there is an example on the wiki
>
> > > > >http://wiki.fluentnhibernate.org/show/AutoMappingTypeConventions
> > > > > > > > > > > > but I just want to store my enum as an Int in the Db and
> > > have
> > > > > it as
> > > > > > > > an
> > > > > > > > > > > > enum in my object and not go to the
> > > > > > > > > > > > length of implementing IUserType.
>
> > > > > > > > > > > > I think I need to add an ITypeConvention to handle my
> > > > > EnumType and
> > > > > > > > add
> > > > > > > > > > > > a custom attribute to describe
> > > > > > > > > > > > the type of my enum?
>
> > > > > > > > > > > > Am I along the right lines here?
>
> > > > > > > > > > > > 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 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