Thanks.

In my 'easy' example, SubTypeType would go away (I'd just use Type) if I
don't try to make the mapping work with the other existing multiple tables.
(Your example solves this.)

In the 'complicated' example, SubTypeType would replace the functionality of
Type in the easy example, and Type would NOT be stored in the database
(might not even be a property? idk): I don't think it makes sense to have a
column on every one of the different tables (for different child types)
indicating that it comes from that table. In other words, in a given table,
EVERY row would have the same value.

(perhaps that's how it needs to be, as I don't know of a way to tell
Fluent/Hibernate to ignore a property: aka, don't try to map it. In fact,
this is why I had to create a 'temporary' DBUser class to load my users from
the database, because I couldn't change the CLR User object to have all
virtual properties :-x. I suppose what I did for User I could do for all
these other types ... )

------
Joe Brockhaus
[email protected]
------


On Thu, Jan 27, 2011 at 4:37 AM, James Gregory <[email protected]>wrote:

> You're not doing basic inheritance mapping.
>
> You can't have multiple discriminator columns. If that's what you're trying
> to do with your SubTypeType, then it isn't going to work. You have one
> discriminator column for the entire table.
>
> To map a table-per-hierarchy with Fluent NHibernate you do this:
>
> public class EntityBaseMap : ClassMap<EntityBase>
> {
>   public EntityBaseMap()
>   {
>     Id(x => x.Id);
>
>     DiscriminateSubclassesOnColumn("Type");
>   }
> }
>
> public class EntityChildAMap : SubclassMap<EntityChildA>
> {
> }
>
> public class EntityChildBMap : SubclassMap<EntityChildB>
> {
> }
>
> That will create a single table for all the subclasses. If you want them to
> have their own tables, remove the Discriminate method call.
>
> A subclass doesn't have a unique identifier, hence the lack of the Id
> method in SubclassMap, as it inherits that identifier from the class it
> extends. If you need to use a different column name for the primary key in
> the table, then you should use the KeyColumn method from inside your
> SubclassMap.
>
> --
> 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]<fluent-nhibernate%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>

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