c# - How to map a related table with no primary key with fluent-NHibernate -


looks common situation me: have 2 tables: documents: did (pk, int), dname(varchar)

and document_options: did (int), otype(int), ovalue(varchar)

i have class document property options (a list of documentoption class)

since document_options has no pk cannot use hasmany, , rows table don't seem 'real' entities anyway...

i see way generate auto-number key document options , map hasmany, or maybe create composite id, i'd know if there better option don't know about.

in case, documentoptions value object, since has no identity of own , has no meaning outside of document belongs to. so, use component map collection properties value object.

public class document : entity // don't worry entity; it's base type created contains id property {     public virtual string name { get; set; }      public virtual ilist<documentoptions> options { get; protected set; }      public document()     {         options = new list<documentoptions>();     } }  public class documentoptions {     public virtual int type { get; set; }      public virtual string value { get; set; } } 

and mapping:

public documentmap() {     table("documents");      id(c => c.id)         .column("did")         .generatedby.hilo("10");      map(c => c.name)         .column("dname");      hasmany(c => c.options)         .component(c =>                        {                            c.map(c2 => c2.value).column("ovalue");                            c.map(c2 => c2.type).column("otype");                        })         .table("document_options")         .keycolumn("did")         .cascade.alldeleteorphan();  } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -