Thanks James.  That won't compile.

Argument '2': cannot convert from 'int' to
'S2sol.Rpo.Core.Domain.User.UserRole'

I'm storing the string value of the enum in my User table.  I actually
don't have a table designed yet, so I could make changes to my
mappings if that would help.



On Jul 16, 10:37 am, James Gregory <[email protected]> wrote:
> This shouldn't be necessary, but try explicitly casting your enum to an int.
> mapping.DiscriminateSubClassesOnColumn<UserRole>("Role",
> (int)UserRole.Teacher)
>
> On Thu, Jul 16, 2009 at 4:31 PM, Corey Coogan <[email protected]> wrote:
>
> > I've searched everywhere and can't find an example that fits this. I
> > really could use some help I keep getting the error:
>
> > "Could not format discriminator value to SQL string of entity..."
>
> > I have a User class with an enum property, UserRole, that I want to be
> > my discriminator.
>
> > public abstract class User
> > {
> >   public string Name;
> >   public virtual UserRole Role { get; protected set; }
> > }
>
> > I then have a subclass for each role:
>
> > public class Teacher : User
> >    {
> >        public Teacher()
> >        {
> >            Role = UserRole.Teacher;
> >        }
>
> >    }
>
> > I don't have any property on Teacher referring to Role because I don't
> > need it.  This is different from what I've seen in other examples.
> > Here's how I tried to map it on my User mapping:
>
> > mapping.DiscriminateSubClassesOnColumn<UserRole>("Role",
> > UserRole.Teacher)
> >                .SubClass<Teacher>(t =>
> >                    {
> >                        t.Map(x => x.Role);
> >                    }
> >            );
>
> > Here's my mapping output:
>
> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
> > access="">
> >  <class name="S2sol.Rpo.Core.Domain.User.User, S2sol.Rpo.Core,
> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="Users"
> > xmlns="urn:nhibernate-mapping-2.2" discriminator-value="Teacher">
> >    <id name="Id" type="Int32" unsaved-value="0" column="Id">
> >      <generator class="identity" />
> >    </id>
> >    <discriminator column="Role"
> > type="S2sol.Rpo.Core.Domain.User.UserRole, S2sol.Rpo.Core,
> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
> >    <property name="Email" type="String" unique-
> > key="IX_Unique_EmailAddress">
> >      <column name="Email" />
> >    </property>
> >    <property name="Role"
> > type="FluentNHibernate.Mapping.GenericEnumMapper`1
> > [[S2sol.Rpo.Core.Domain.User.UserRole, S2sol.Rpo.Core,
> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]],
> > FluentNHibernate, Version=0.1.0.0, Culture=neutral,
> > PublicKeyToken=8aa435e3cb308880">
> >      <column name="Role" />
> >    </property>
>
> >    <property name="Name" type="String">
> >      <column name="Name" />
> >    </property>
>
> >    <subclass name="S2sol.Rpo.Core.Domain.User.Teacher,
> > S2sol.Rpo.Core, Version=1.0.0.0, Culture=neutral,
> > PublicKeyToken=null">
> >      <property name="Role" type="S2sol.Rpo.Core.Domain.User.UserRole,
> > S2sol.Rpo.Core, Version=1.0.0.0, Culture=neutral,
> > PublicKeyToken=null">
> >        <column name="Role" />
> >      </property>
> >    </subclass>
> >  </class>
> > </hibernate-mapping>
--~--~---------~--~----~------------~-------~--~----~
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