-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Semi complicated object relationship...
PostPosted: Fri Sep 17, 2010 10:29 am 
Newbie

Joined: Fri Sep 25, 2009 8:36 am
Posts: 9
Hello,

I havent touched NHibernate in a few months so im a bit out of touch with it, however ive got a semi complicated relationship between my objecs and tables and im not quite sure how to map them... Its old code that used to use Microsoft EnterpriseLibrary and im trying to convert it over to use NHibernate...

To simplify the problem here is an example of what table structure i have:

Code:
Table1
- Id [Int32]
- Value [Int32]
- TypeId [byte]
...

Table2
- Id [Int32]
- Value [Int32]
- TypeId [byte]
...

TypeTable
- Id [byte]
- Name [Varchar, 30]


Now I have 2 main classes, which both use a 3rd class as a reference to the TypeTable but use it as an enum in the classes... rather than explain here is an example:

Code:
class Class1
{
   int Id { get; set;}
   TypeWithValue<TypeEnum, int> AssociatedValue { get; set; }
   ...
}

class Class2
{
   int Id { get; set;}
   TypeWithValue<TypeEnum, int> AssociatedValue { get; set; }
   ...
}

class TypeWithValue<TEnum, TValue>
{
    TEnum Type { get; set; }
    TValue Value { get; set; }
}

enum TypeEnum
{
   Unknown = 0,
   SomeValue = 1,
   SomeOtherValue = 2
}


Now im not sure how to represent this TypeWithValue with a mapping file, as the 2 classes would have their own mapping files, however they would both need to reference the TypeWithValue class somehow to populate its properties.

The main thing im having difficulty getting my head around is how im going to be able to get the Id for the Enums value from the same table every time, but get the value from a different one depending on the parent class.

If it helps the old SQL was something like this:

Code:

SELECT Table1.*, TableType.Id AS EnumType FROM Table1
JOIN TableType ON TableType.Id = Table1.TypeId
WHERE Table1.Id = X;

SELECT Table2.*, TableType.Id As EnumType FROM Table2
JOIN TableType ON TableType.Id = Table2.TypeId
WHERE Table2.Id = X;



Unfortunately this TypeWithValue<T1,T2> is used in lots of different places to represent an enum with a coresponding value... an example would be something like someones score for a school subject, so you would have the enum value being "LessonType.Geography" and the value being 100 being top score...

I was thinking that its more of a component but its data comes from multiple tables, but i cant make 1 mapping for the TypeWithValue as its Value comes from different places, and i wasnt sure if i could make a mapping for it but exclude Value and pump it in from elsewhere...

Any help would be great, ive tried to be as descriptive with my problem as possible...


Top
 Profile  
 
 Post subject: Re: Semi complicated object relationship...
PostPosted: Fri Sep 17, 2010 10:47 am 
Newbie

Joined: Fri Sep 25, 2009 8:36 am
Posts: 9
Just realised i was being a nugget... A trip to the loo reminded me that i already have the TypeId within the Table1, Table2 so i can use it as a component after all!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.