You need to rethink your design. It's either a fully fledged subclass with a
discriminator, or you just use a User entity that has a Role property; you
can't save with one and query with the other.

On Thu, Aug 13, 2009 at 11:04 PM, AzamSharp <azamsh...@gmail.com> wrote:

>
> The only problem is that I don't want to add another column in the
> Users table. If I like to know who is teacher then I will create a
> UserRoles table and that will be linked with the Users table.
>
> Thanks,
> Azam
>
> On Aug 13, 5:01 pm, James Gregory <jagregory....@gmail.com> wrote:
> > Who said anything about roles?
> > I don't think I can make this any simpler... Add a new column into your
> > Users table called Discriminator, this column will hold the class name
> for
> > that role. *That is all you need to do.*
> >
> > Given this table:
> >
> > | UserId | FirstName | LastName |
> > | 1      | James     | Gregory  |
> > | 2      | Joe       | Bloggs   |
> >
> > Which one is a Teacher? NHibernate cannot tell, we cannot tell. You need
> > another column.
> >
> > | UserId | FirstName | LastName | Discriminator |
> > | 1      | James     | Gregory  | Teacher       |
> > | 2      | Joe       | Bloggs   | User          |On Thu, Aug 13, 2009 at
> 10:57 PM, AzamSharp <azamsh...@gmail.com> wrote:
> >
> > > Forget about the Role information. I am just assigning FirstName and
> > > LastName to a Teacher object. Roles and UserRoles will be different
> > > table since one person can have many roles.
> >
> > > How can I just insert the Teacher's "FirstName" and "LastName" into
> > > the Users table?
> >
> > > On Aug 13, 4:53 pm, James Gregory <jagregory....@gmail.com> wrote:
> > > > You need another column in your Users table to tell NHibernate what
> each
> > > row
> > > > is. How else is it supposed to be able to tell what entity each row
> is?
> >
> > > > On Thu, Aug 13, 2009 at 10:52 PM, AzamSharp <azamsh...@gmail.com>
> wrote:
> >
> > > > > No I don't have a discriminator column. I only have a Users table
> > > > > which has the following fields:
> >
> > > > > UserId, FirstName and LastName.
> >
> > > > > There is not even a Teacher table or a Student table. Teacher and
> > > > > Student both uses the Users table to store the information.
> >
> > > > > On Aug 13, 4:48 pm, James Gregory <jagregory....@gmail.com> wrote:
> > > > > > Do you have a column name called discriminator?
> > > > > > You need a column in your table which tells NHibernate what the
> > > entity a
> > > > > row
> > > > > > represents, that is what you put in the
> > > DiscriminateSubClassesOnColumn
> > > > > call.
> >
> > > > > > On Thu, Aug 13, 2009 at 10:46 PM, AzamSharp <azamsh...@gmail.com
> >
> > > wrote:
> >
> > > > > > > Now it is throwing invalid column name discriminator:
> >
> > > > > > >  public class UserMap : ClassMap<User>
> > > > > > >    {
> > > > > > >        public UserMap()
> > > > > > >        {
> > > > > > >            Id(x => x.Id).ColumnName("UserId");
> > > > > > >            Map(x => x.FirstName);
> > > > > > >            Map(x => x.LastName);
> > > > > > >            WithTable("Users");
> >
> > > > > > >            DiscriminateSubClassesOnColumn("discriminator")
> > > > > > >                 .SubClass<Teacher>(m => { });
> >
> > > > > > >        }
> > > > > > >    }
> >
> > > > > > > On Aug 13, 4:45 pm, James Gregory <jagregory....@gmail.com>
> wrote:
> > > > > > > > Then just leave the mapping empty!
> > > > > > > > SubClass<Teacher>(m => {});
> >
> > > > > > > > On Thu, Aug 13, 2009 at 10:44 PM, AzamSharp <
> azamsh...@gmail.com
> >
> > > > > wrote:
> >
> > > > > > > > > Teacher does not have anything extra. It only uses the
> > > inherited
> > > > > > > > > fields from the User class!
> >
> > > > > > > > > On Aug 13, 4:43 pm, James Gregory <jagregory....@gmail.com
> >
> > > wrote:
> > > > > > > > > > No you don't need to remap them. Just map anything that
> > > *only*
> > > > > > > appears on
> > > > > > > > > > Teacher inside the SubClass<Teacher> call.
> >
> > > > > > > > > > On Thu, Aug 13, 2009 at 10:42 PM, AzamSharp <
> > > azamsh...@gmail.com
> >
> > > > > > > wrote:
> >
> > > > > > > > > > > Here is my code:
> >
> > > > > > > > > > > public class UserMap : ClassMap<User>
> > > > > > > > > > >    {
> > > > > > > > > > >        public UserMap()
> > > > > > > > > > >        {
> > > > > > > > > > >             Id(x => x.Id).ColumnName("UserId");
> > > > > > > > > > >            Map(x => x.FirstName);
> > > > > > > > > > >            Map(x => x.LastName);
> > > > > > > > > > >            WithTable("Users");
> >
> > > > > > > > > > >
>  DiscriminateSubClassesOnColumn("discriminator")
> > > > > > > > > > >                .SubClass<Teacher>(
> >
> > > > > > > > > > >                m =>
> > > > > > > > > > >                    {
> > > > > > > > > > >                         // do I have to define the
> mappings
> > > > > again
> > > > > > > for
> > > > > > > > > > > teacher. teacher inherit from User so it should map
> > > > > "FirstName",
> > > > > > > > > > > "LastName" and "Id" automatically!
> > > > > > > > > > >                    }
> >
> > > > > > > > > > >                );
> >
> > > > > > > > > > >        }
> > > > > > > > > > >    }
> >
> > > > > > > > > > > On Aug 13, 4:38 pm, James Gregory <
> jagregory....@gmail.com
> >
> > > > > wrote:
> > > > > > > > > > > > You haven't mapped your teacher.
> > > > > > > > > > > > public class UserMap : ClassMap<User>
> > > > > > > > > > > > {
> > > > > > > > > > > >   public UserMap()
> > > > > > > > > > > >   {
> > > > > > > > > > > >     Id(x => x.Id);
> > > > > > > > > > > >     Map(x => x.PropertyInUser);
> >
> > > > > > > > > > > >     //
> > > > > > > > > > > >     // mappings on User and all subclasses here
> > > > > > > > > > > >     //
> >
> > > > > > > > > > > >     DiscriminateSubClassesOnColumn("discriminator")
> > > > > > > > > > > >       .SubClass<Teacher>(m =>
> > > > > > > > > > > >       {
> > > > > > > > > > > >         // any mappings ONLY on teacher here
> > > > > > > > > > > >       });
> > > > > > > > > > > >   }
> >
> > > > > > > > > > > > }
> > > > > > > > > > > > On Thu, Aug 13, 2009 at 10:34 PM, AzamSharp <
> > > > > azamsh...@gmail.com
> >
> > > > > > > > > wrote:
> >
> > > > > > > > > > > > > I have a scenario where I have a base class called
> > > "User"
> > > > > and I
> > > > > > > > > have
> > > > > > > > > > > > > inherited classed called "Teacher" and "Student". I
> > > have
> > > > > define
> > > > > > > > > some
> > > > > > > > > > > > > properties in the User class which are also used in
> the
> > > > > Teacher
> > > > > > > and
> > > > > > > > > > > > > Student through inheritance. I have defined the
> UserMap
> > > > > with
> > > > > > > all
> > > > > > > > > the
> > > > > > > > > > > > > mappings. But it throws error when I try to save
> the
> > > > > Teacher
> > > > > > > saying
> > > > > > > > > > > > > "Persister is not defined".
> >
> > > > > > > > > > > > > Thanks,
> > > > > > > > > > > > > Azam
> >
> > > > > > > > > > > > > On Aug 13, 4:29 pm, James Gregory <
> > > jagregory....@gmail.com
> >
> > > > > > > wrote:
> > > > > > > > > > > > > > DiscriminateSubClassOnColumn is only to be used
> for
> > > the
> > > > > > > > > discriminator
> > > > > > > > > > > > > > column, the column in your table that dictates
> what
> > > > > entity
> > > > > > > type
> > > > > > > > > the
> > > > > > > > > > > row
> > > > > > > > > > > > > > contains.
> > > > > > > > > > > > > > All other properties are mapped normally.
> >
> > > > > > > > > > > > > > On Thu, Aug 13, 2009 at 10:10 PM, AzamSharp <
> > > > > > > azamsh...@gmail.com
> >
> > > > > > > > > > > wrote:
> >
> > > > > > > > > > > > > > > Hi,
> >
> > > > > > > > > > > > > > > I just looked at the syntax for
> > > > > > > > > DiscriminateSubClassesOnColumn()
> > > > > > > > > > > which
> > > > > > > > > > > > > > > is little weird but anyway!!
> >
> > > > > > > > > > > > > > > It seems like I have to create a
> > > > > > > DiscriminateSubClassesOnColumn
> > > > > > > > > for
> > > > > > > > > > > > > > > every column that is being used in the Base
> class.
> > > Is
> > > > > that
> > > > > > > > > right?
> > > > > > > > > > > That
> > > > > > > > > > > > > > > will be a disaster for me since I have several
> > > fields
> > > > > in
> > > > > > > the
> > > > > > > > > sub
> > > > > > > > > > > > > > > classes which are inherited from the base
> class.
> >
> > > > > > > > > > > > > > > Thanks,
> > > > > > > > > > > > > > > Azam
> >
> > > > > > > > > > > > > > > On Aug 12, 9:55 am, Hudson Akridge <
> > > > > > > hudson.akri...@gmail.com>
> > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > > Definitely. :) Think of it this way, how else
> > > would
> > > > > NH
> > > > > > > know
> > > > > > > > > about
> > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > Teacher, or more importantly, how to
> rehydrate a
> > > > > Teacher
> > > > > > > > > instead
> > > > > > > > > > > of a
> > > > > > > > > > > > > > > User
> > > > > > > > > > > > > > > > whenever you retrieve information from that
> row.
> > > It's
> > > > > > > that
> > > > > > > > > > > > > discriminator,
> > > > > > > > > > > > > > > > when you persist a Teacher, it needs to know
> how
> > > to
> > > > > flag
> > > > > > > it
> > > > > > > > > as a
> > > > > > > > > > > > > Teacher
> > > > > > > > > > > > > > > > class, and separate it from a User class. In
> > > order
> > > > > for it
> > > > > > > to
> > > > > > > > > do
> > > > > > > > > > > that,
> > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > have to tell it what the Teacher's
> discriminator
> > > is
> > > > > going
> > > > > > > to
> > > > > > > > > be,
> > > > > > > > > > > and
> > > > > > > > > > > > > tie
> > > > > > > > > > > > > > > it
> > > > > > > > > > > > > > > > to the Teacher type.
> >
> > > > > > > > > > > > > > > > On Wed, Aug 12, 2009 at 9:53 AM, AzamSharp <
> > > > > > > > > azamsh...@gmail.com>
> > > > > > > > > > > > > wrote:
> >
> > > > > > > > > > > > > > > > > What is the Teacher does not exposes any
> > > additional
> > > > > > > > > attributes
> > > > > > > > > > > and
> > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > same as the User class? Do I still have to
> use
> > > the
> > > > > > > > > > > > > > > > > DiscriminateSubclasses in the UserMap?
> >
> > > > > > > > > > > > > > > > > Thanks,
> > > > > > > > > > > > > > > > > Azam
> >
> > > > > > > > > > > > > > > > > On Aug 12, 9:47 am, Hudson Akridge <
> > > > > > > > > hudson.akri...@gmail.com>
> > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > > > > Even with no specific attributes on
> Teacher
> > > > > (which if
> > > > > > > all
> > > > > > > > > > > you've
> > > > > > > > > > > > > got
> > > > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > different behavior, you may want to look
> at
> > > the
> > > > > State
> > > > > > > > > > > pattern),
> > > > > > > > > > > > > you
> > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > need to register Teacher as a subclass
> with
> > > > > FNH/NH,
> > > > > > > and
> > > > > > > > > you
> > > > > > > > > > > do
> > > > > > > > > > > > > that
> > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > declaring it on the
> DiscriminateSubclasses
> > > FNH
> > > > > method
> > > > > > > in
> > > > > > > > > your
> > > > > > > > > > > > > > > UserMap.
> >
> > > > > > > > > > > > > > > > > > On Wed, Aug 12, 2009 at 9:45 AM,
> AzamSharp <
> > > > > > > > > > > azamsh...@gmail.com>
> > > > > > > > > > > > > > > wrote:
> >
> > > > > > > > > > > > > > > > > > > Hi,
> >
> > > > > > > > > > > > > > > > > > > Thanks for the reply!
> >
> > > > > > > > > > > > > > > > > > > Teacher inherits from User class and
> there
> > > is
> > > > > only
> > > > > > > > > Users
> > > > > > > > > > > table
> > > > > > > > > > > > > in
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > database.
> >
> > > > > > > > > > > > > > > > > > > User class has a UserMap which defines
> the
> > > > > mapping
> > > > > > > for
> > > > > > > > > the
> > > > > > > > > > > > > User.
> > > > > > > > > > > > > > > > > > > Teacher does not define any mapping. If
> I
> > > don't
> > > > > > > have
> > > > > > > > > any
> > > > > > > > > > > > > mapping
> > > > > > > > > > > > > > > for
> > > > > > > > > > > > > > > > > > > Teacher then it gives error for
> "persister
> > > not
> > > > > > > > > defined".
> >
> > > > > > > > > > > > > > > > > > > Thanks,
> > > > > > > > > > > > > > > > > > > Azam
> >
> > > > > > > > > > > > > > > > > > > On Aug 12, 9:38 am, James Gregory <
> > > > > > > > > jagregory....@gmail.com
> >
> > > > > > > > > > > > > wrote:
> > > > > > > > > > > > > > > > > > > > I was actually referring to what Azam
> is
> > > > > trying
> > > > > > > to do
> > > > > > > > > :)
> >
> > > > > > > > > > > > > > > > > > > > You should never need to subclass
> your
> > > > > ClassMap.
> >
> > > > > > > > > > > > > > > > > > > > On Wed, Aug 12, 2009 at 3:30 PM,
> Hudson
> > > > > Akridge <
> > > > > > > > > > > > > > > > > > > hudson.akri...@gmail.com>wrote:
> >
> > > > > > > > > > > > > > > > > > > > > Absolutely correct :) I might have
> > > > > > > misunderstood
> > > > > > > > > what
> > > > > > > > > > > the
> > > > > > > > > > > > > OP
> > > > > > > > > > > > > > > was
> > > > > > > > > > > > > > > > > > > asking, I
> > > > > > > > > > > > > > > > > > > > > assumed that he wanted to extend
> the
> > > > > mappings
> > > > > > > for
> > > > > > > > > > > Teacher
> > > > > > > > > > > > > from
> > > > > > > > > > > > > > > his
> > > > > > > > > > > > > > > > > > > UserMap.
> >
> > > > ...
> >
> > > > read more ยป
> >
>

--~--~---------~--~----~------------~-------~--~----~
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