What I need to achive is:

CRUD for Car (piece of cake due to is a single object)
CRUD for RacingCar. The issue here is that some properties shuld mapp
a field in Car table.

So I can get 100 records in Car table and 20 in RacingCar. The 20 RC
are related to a car by a foreing key "id_car".
Unfortunately I cannot change DB definition but I can play with object
model and NHibernate mapping.
The problem is I'm still a begginer using NHibernate.

Thanks a lot for your time and answers!!



On 8 jun, 12:47, Julian <[email protected]> wrote:
> I agree with Oskar: Inheritance doesn't seem the right approach here
> if it is really possible to delete RacingCar, but not Car. Perhaps
> they could be two separate entities with a one-to-one relationship? Or
> maybe CarRacing could be a Car decorator (http://www.dofactory.com/
> Patterns/PatternDecorator.aspx)?
>
> On Jun 8, 7:59 pm, Oskar Berggren <[email protected]> wrote:
>
>
>
> > Well... if a RacingCar will always remain a RacingCar, a Taxi always
> > remain a Taxi, then inheritance might be a workable solution.
>
> > Forget about the tables for a moment. Consider the object model and
> > your business logic:
>
> > > Creating a Car doesn't create a CarRacing.
>
> > That would mean you have an instance of the base class Car, which is
> > fine technically if that is allowed by your logic.
>
> > > Deleting a CarRacing doesn't delete a Car.
>
> > Weirdness! In an object model using inheritance, there is no such
> > thing as deleting "half" an object and expecting the remainder to
> > morph to a different class. (The closest thing is delete the
> > RacingCar, then create a new instance of base class Car with the same
> > relevant information.)
>
> > So if you business logic as given is really what you want, then it's
> > not inheritance you need. It's more like a Car "has a" CurrentUsage,
> > where current usage may be a RacingCar instance or a Taxi instance.
>
> > Some options seem to occur here... You could have RacingCar and Taxi
> > inherit from abstract base class CarUsage, with the Car class having a
> > Usage property of type CarUsage. Alternatively, you could let
> > RacingCar and Taxi classes each point to the physical Car instance,
> > but without having Car.Usage. Or you could mix both approaches if you
> > need bidirectionality.
>
> > You might also want to study the State design pattern.
>
> > /Oskar
>
> > 2010/6/8 Eddie <[email protected]>:
>
> > > We have a master table Cars. So every car created is saved in the
> > > table car.
>
> > > Then we have different types of cars. RacingCar, Taxies, etc. Every
> > > type has a table with the particular information about the type. E.j.
> > > the field 'number' in RacingCar.
>
> > > So, I want to get the racingcar in my DB I do a select joining tables
> > > car and racingcar or if I want to get taxis I join tables car and
> > > taxies.
>
> > > It is the same when having tables like 'Person', 'Clients' and
> > > 'Sellers'. The name and lastname resides in 'Persons' table but not in
> > > 'clients' or 'sellers'.
>
> > > Now we are moving to NHibernate and I face this hierarchy issues. I'm
> > > reading the documentation but I don't see clearly the way to go on.
>
> > > Thanks.
>
> > > On 8 jun, 08:17, Oskar Berggren <[email protected]> wrote:
> > >> Eddie, can you give some more information on what real life concept
> > >> the RacingCar captures?
>
> > >> /Oskar
>
> > >> 2010/6/8 Julian <[email protected]>:
>
> > >> > When you use inheritance you should usually have an 'is a'
> > >> > relationship. For example, a TextBox inherits from Control because a
> > >> > TextBox 'is a' type/kind of Control. The properties on your RacingCar
> > >> > would suggest it is not a type of Car; perhaps it is a Team which has
> > >> > a collection of Cars? This changes the mapping altogether - and makes
> > >> > it much simpler than what you are trying to achieve.
>
> > >> > public class Team
> > >> > {
> > >> >  public string Name { get; set; }
> > >> >  public List<Car> Cars { get; set; }
> > >> > }
>
> > >> > Number of cars is: Team.Cars.Count
>
> > >> > On Jun 8, 3:56 am, Eddie <[email protected]> wrote:
> > >> >> Hi.
> > >> >> I'm starting with NHibernate. I need to map 2 tables to 1 entity but
> > >> >> one of the tables is already mapped to another entity.
> > >> >> I coudl ilustrated as follow:
>
> > >> >> Table Car (Id int identity, model varchar)
> > >> >> Table RacingCar ( id int identity, id_car int, numberInRace int, team
> > >> >> string)
>
> > >> >> So I got a Car entity and a CarRacing entity.
>
> > >> >>     public class Car
> > >> >>     {
> > >> >>         private int _id;
> > >> >>         private string _model;
>
> > >> >>         public int ID
> > >> >>         {
> > >> >>             get { return _id; }
> > >> >>             set { _id= value; }
> > >> >>         }
>
> > >> >>         public string Model
> > >> >>         {
> > >> >>             get { return _model; }
> > >> >>             set { _model= value; }
> > >> >>         }
>
> > >> >>     }
>
> > >> >>     public class CarRacing : Car
> > >> >>     {
> > >> >>         private int _number;
> > >> >>         private string _team;
>
> > >> >>         public int Number
> > >> >>         {
> > >> >>             get { return _number; }
> > >> >>             set { _number= value; }
> > >> >>         }
>
> > >> >>         public string Team
> > >> >>         {
> > >> >>             get { return _team; }
> > >> >>             set { _team= value; }
> > >> >>         }
> > >> >>     }
>
> > >> >> The mapping for Car entity doesn't bring any dificulties. The issue is
> > >> >> how to map CarRacing taking in count the inheritance and the bussines
> > >> >> restrictions.
>
> > >> >> Creating a Car doesn't create a CarRacing.
> > >> >> Deleting a Car does delete a CarRacing.
>
> > >> >> Creating a CarRacing does create a Car.
> > >> >> Deleting a CarRacing doesn't delete a Car.
> > >> >> Updating a CarRacing updates Car and CarRacing.
>
> > >> >> I need some tips or guidance about how to mapp this hierarchy and get
> > >> >> the requested behaviour.
>
> > >> >> Thanks in advance.
>
> > >> > --
> > >> > You received this message because you are subscribed to the Google 
> > >> > Groups "nhusers" 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 
> > >> > athttp://groups.google.com/group/nhusers?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "nhusers" 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 
> > > athttp://groups.google.com/group/nhusers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to