nhibernate - Map a column multiple times -


i have rather odd requirement in fluent hibernate maps. have table(a) has compound foreign key relationship table(b). in mapping table have both object created table b , access individual attributes of define key. there way that? seem index out of range exceptions if map column twice.

i cannot explore b attributes because row in table b may not exist. painfully aware there significant smells in structure i'm dealing. such fate of deal legacy systems.

it's kinda possible, hacking around little.

we're going define domain fake collection we'll use retrieve single related element, if found:

public class foo {     public virtual barkey barkey { get; set; }     public virtual bar bar { { return bars.singleordefault(); } }     protected virtual icollection<bar> bars { get; set; } }  public class bar {     public virtual barkey id { get; set; } }  //this class must override equals , gethashcode. implementation not shown. public class barkey {     public virtual int x { get; set; }     public virtual int y { get; set; } } 

the barkey component contains properties part of key.

now, mapping:

<class name="foo">   <id ...><generator .../></id>   <component name="barkey">     <property name="x" />     <property name="y" />   </component>   <bag name="bars" inverse="true">     <key property-ref="barkey">       <column name="x"/>       <column name="y"/>     </key>     <one-to-many class="bar"/>   </bag> </class> <class name="bar">   <composite-id name="id">     <key-property name="x" />     <key-property name="y" />   </composite-id> </class> 

the property-ref attribute there tells nh match columns in bar against barkey property of foo instead of id.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -