Create some views and then work with those views instead that wonderful table

--
Fabio Maulo


El 22/10/2010, a las 13:23, Brian Chavez <[email protected]> escribió:

> Hi Fabio,
>
> My table has 140 different columns.
>
> Mapping 1 entity to 140 different columns is very hard, especially on
> performance. I do not want to transmit 140 columns of data for each
> row over the wire per request / result set.
>
> In addition, my entity in C# would have 140 properties. This is not
> good.
>
> Therefore, I need to selectively map only the columns (properties) I'm
> interested in.
>
> class A {
>   int Id{get;set}
>   AProperty{get;set;}
> }
>
> Class A is the minimum amount of information I need in this class
> hierarchy. Derived sub-classes of A would represent different
> projections of the data in Table 1 of a row.
>
> class B : A {
>   BProperty{get;set;}
>   ...etc. //AProperty is inherited. So is Id
> }
>
> I want to tell NHibernate to give me a view of row 5 that looks like A
> when I CreateCriteria(typeof(A)).WhereIdEquals(5).
> I want to tell NHibernate to give me a view of row 5 that looks like C
> (which has extra column/property) when I
> CreateCriteria(typeof(C)).WhereIdEquals(5).
>
> A row in the DB can be represented by A, B, or C (depending on which
> type I request). Each type has a different projection of the same row.
>
> I'm trying to avoid using AliasToBean transformer.
>
> Thanks,
> Brian
>
>
> On Oct 22, 8:40 am, Fabio Maulo <[email protected]> wrote:
>> A row in the DB is the representation of the state of one object: which one?
>>
>> --
>> Fabio Maulo
>>
>> El 22/10/2010, a las 12:05, Brian Chavez <[email protected]> escribió:
>>
>> Hi Fabio,
>>
>> Row 5 can be A, B, and C, depending on which one I'm requesting.
>>
>> The class hierarchy at A implements Id.
>>
>> class A{
>>   int Id{get;set;}
>>   AProperty{get;set;} //Mapped to ColumnA in Table 1
>>
>> }
>>
>> class B : A {
>>    BProperty{get;set;} //Mapped to ColumnB in Table 1
>>
>> }
>>
>> class C : B {
>>    CProperty{get;set;} //Mapped to ColumnC in Table 1
>>
>> }
>>
>> B and C only map extra properties which are column projections.
>>
>> CreateCriteria(typeof(A)).Add(Expression.Eq("Id",
>> 5)).UniqueResult<A>()
>> CreateCriteria(typeof(C)).Add(Expression.Eq("Id",
>> 5)).UniqueResult<C>()
>>
>> The Database Identity of A and C are the same.
>> The only difference is that C includes C.AProperty, C.BProperty, and
>> C.CProperty projection. Where as A only has A.AProeprty projection.
>>
>> Thanks,
>> Brian
>>
>> On Oct 22, 7:54 am, Fabio Maulo <[email protected]> wrote:
>>
>> A row in the DB is the representation of the state of one object: which one?
>>
>> --
>>
>> Fabio Maulo
>>
>> El 22/10/2010, a las 11:40, Brian Chavez <[email protected]> escribió:
>>
>> Hi Alan,
>>
>> Thanks so much for the reply. I'm trying to avoid NHibernate using the
>>
>> database to determine the type of object.
>>
>> A single row in Table 1 can be projected into any object in the class
>>
>> hierarchy.
>>
>> For example, Row 5 is A, B, or C; depending on which type I'm
>>
>> requesting.
>>
>> If I CreateCriteria(typeof(C)), then NHibernate has enough information
>>
>> to know what type I'm requesting.
>>
>> I don't want NHibernate to extract type information from the database
>>
>> (ie: discriminator) because class A, B, and C can all represent any
>>
>> row in Table 1.
>>
>> The only difference between A, B, and C classes is the projections of
>>
>> the columns in the table.
>>
>> I hope that clarifies my situation.
>>
>> Any feedback would be appreciated!
>>
>> -Brian
>>
>> On Oct 22, 7:13 am, "[email protected]"
>>
>> <[email protected]> wrote:
>>
>> You can use formulas as discriminators as opposed to a column.  You
>>
>> obviously have some sort of logic that determines the object type?
>>
>> On Oct 22, 9:02 am, Brian Chavez <[email protected]> wrote:
>>
>> Hello.
>>
>> Problem:
>>
>> I have 1 very large table of columns.
>>
>> I have a class hierarchy that represents different projections of the
>>
>> columns of this table.
>>
>> For example:
>>
>> class A{
>>
>>    AProperty{get;set;} //Mapped to ColumnA in Table 1
>>
>> }
>>
>> class B : A {
>>
>>     BProperty{get;set;} //Mapped to ColumnB in Table 1
>>
>> }
>>
>> class C : B {
>>
>>     CProperty{get;set;}
>>
>> }
>>
>> When I ask NHibernate to pull C, I expect to see C.AProperty,
>>
>> C.BProperty, and C.CProperty.
>>
>> Essentially, this class hierarchy represents different scoped
>>
>> projected views of the *same* table.
>>
>> How do I do this in hbm.xml mapping files without adding discriminator
>>
>> values?
>>
>> I've tried to use multiple <union-subclass> attributes and map to the
>>
>> same table, but NH throws an exception:
>>
>> --> NHibernate.DuplicateMappingException : Duplicate table mapping
>>
>> Table 1
>>
>> Any ideas?
>>
>> Thanks,
>>
>> Brian
>>
>> --
>>
>> 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.
>

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