The class-to-table mappings are nice and easy - the harder part (IMO) of
the problem is maintaining type-safety for the 'group' types.  These
should, I think, have a signature along the lines of

 

class AnimalGroup<T> where T:Animal

 

class AnimalGroupMember<T> where T:Animal

                T AnimalMember { get; set; }

 

to prevent cats & dogs being accidentally mixed together with the
resultant flying fur^H^H^H exceptions.   As above with single-ended
assocations is not a problem - but if you wire things bidirectionally
then suddenly it gets a lot harder:

 

class AnimalGroupMember<T> where T:Animal

                T Member { get; set; }

                AnimalGroup<T> Group { get; set; }

 

class Animal

     ICollection<AnimalGroupMember<? what goes here ?>> GroupMemberShips


 

I've yet to find a 'clean' solution for this that I'm 100% happy with
... all of my attempts have resulted in either class-bloat, casts or
a-priori knowledge of concrete Animal types.

 

/Pete

 

 

From: [email protected] [mailto:[email protected]] On
Behalf Of Fran Knebels
Sent: 13 March 2013 16:12
To: [email protected]
Subject: Re: [nhusers] Mapping property of BaseClass type

 

another good blog entry for loquacious mapping.

On Wednesday, March 13, 2013, Roger Kratz wrote:

http://nhforge.org/doc/nh/en/index.html#inheritance-tableperconcrete

 

 

From: [email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');>
[mailto:[email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');> ] On
Behalf Of mouthbow
Sent: den 13 mars 2013 16:28
To: [email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');> 
Subject: [nhusers] Mapping property of BaseClass type

 

Hi, I'm trying to make this mapping and I think it must be simple but
I'm not getting the way.

 

Suppose in one side I have three clases:

 

-Animal

-Dog : Animal

-Cat : Animal

 

public abstract class Animal {

        public Guid Id { get; set; }

        public String Name { get; set; }

    }

 

public class Dog : Animal

{

     public datetime WalkHour  {get; set;}

}

 

public class Cat : Animal

{

     public int MeaowCount {get; set;}

}

 

 

 

And in the other side I have other two classes:

 

-AnimalGroup

-AnimalGroupMember

 

 

public class AnimalGroup

{

        public Guid Id { get; set; }

        public String Name { get; set; }

}

 

 

public class AnimalGroupMember

{

     public Guid Id {get; set;}

     public Animal AnimalMember {get; set;} 

}

 

 

As you can see, what I want is that my AnimalGroupMembers can be any
kind of Animal but I want to get the correct type of Animal in the
property AnimalMember (obviously casting to its type). I also need to
keep separately in Database: one table for Cats and one Table for Dogs
and I don't want to have any table called Animal.

 

Please help me in doing this, I really need this solution.

 

Thanks for reading and for helping.<

-- 
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'nhusers%[email protected]
om');> .
To post to this group, send email to [email protected]
<javascript:_e(%7b%7d,%20'cvml',%20'[email protected]');> .
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google
Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
!DSPAM:1,5140a5991878246432633! 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to