Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate.Mapping.ByCode Many-to-Many relations
    primarykey
    data
    text
    <p>I've created 2 objects:</p> <pre><code>public class Set { public Set() { _sorts = new List&lt;Sort&gt;(); } public virtual int Id { get; set; } public virtual string Code { get; set; } private ICollection&lt;Sort&gt; _sorts; public virtual ICollection&lt;Sort&gt; Sorts { get { return _sorts; } set { _sorts = value; } } } public class Sort { public Sort() { _sets = new List&lt;Set&gt;(); } public virtual int Id { get; set; } public virtual string Name { get; set; } private ICollection&lt;Set&gt; _sets; public virtual ICollection&lt;Set&gt; Sets { get { return _sets; } set { _sets = value; } } } </code></pre> <p>And 2 mappings:</p> <pre><code>public class SetMapping: ClassMapping&lt;Set&gt; { public SetMapping() { Table("Sets"); Id(x =&gt; x.Id, map =&gt; map.Generator(IdGeneratorSelector.CreateGenerator())); Property(x =&gt; x.Code, map =&gt; { map.Length(50); map.NotNullable(false); }); Bag(x =&gt; x.Sorts, map =&gt; { map.Key(k =&gt; { k.Column("SetId"); k.NotNullable(true); }); map.Cascade(Cascade.All); map.Table("SetsToSorts"); map.Inverse(true); }, r =&gt; r.ManyToMany(m =&gt; m.Column("SortId"))); } } public class SortMapping: ClassMapping&lt;Sort&gt; { public SortMapping() { Table("Sorts"); Id(x =&gt; x.Id, map =&gt; map.Generator(IdGeneratorSelector.CreateGenerator())); Property(x =&gt; x.Name, map =&gt; { map.Length(50); map.NotNullable(false); }); } } </code></pre> <p>usage: Set can have many sorts Sort can belong to many sets.</p> <p>And I would like to use this as:</p> <pre><code>var set = new Set() {Code = "001"}; var sort = new Sort {Name = "My name"}; set.Sorts.Add(sort); sort.Sets.Add(set); </code></pre> <p>Somehow the relations are not working yet because when I try to use the above code to add sorts to set for example and commit then I don't see any records saved to the SetsToSorts linked table.</p> <p>Does anyone have a clue what I'm missing in my mapping? Or otherwise doing wrong?</p> <p>Thank you, Joost</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload