Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate - Add where clause to columns mapped to a list
    primarykey
    data
    text
    <p>By implementing <code>ICompositeUserType</code>, about 100 columns have been mapped to an <code>IList&lt;IdentifiedValue&gt;</code>. This is an object containing the name of the column and its value.</p> <pre><code>public class IdentifiedValue { public string Name; public object Value; } public class CompanyContainer { public virtual IList&lt;IdentifiedValue&gt; Values; } </code></pre> <p>How can I now filter on one of these columns?</p> <pre><code>string columnToFilter = "Col1"; object needle = "12345A"; IQueryOver&lt;CompanyContainer, CompanyContainer&gt; query = ... // This crashes (as somewhat expected) query.Where(cc =&gt; cc.Values.Single(attr =&gt; attr.Name == columnToFilter).Value == needle); // I sort of expected this to work: query.Where(Restrictions.Eq(columnToFilter, needle)); </code></pre> <p>Unfortunately those approaches don't work.</p> <p>The fluent mapping to the IList is as follows:</p> <pre><code>var columnDefinitions = new string[] {"Col1", "Col2"}; var cols = Map(x =&gt; x.Values) .CustomType&lt;IdentifiedValueMapper&gt;() .Columns.Clear(); foreach (var column in columnDefinitions) { cols.Columns.Add(column.Name) } public class IdentifiedValueMapper : ICompositeUserType { public string[] PropertyNames { get { var result = new List&lt;string&gt;(); foreach (var column in columnDefinitions) { result.Add(column.Name); } return result.ToArray(); } } public IType[] PropertyTypes { get { var result = new List&lt;IType&gt;(); foreach (string columnName in columnDefinitions) { result.Add(NHibernateUtil.Int32); } } } public Type ReturnedClass { get { return typeof (List&lt;IdentifiedValue&gt;); } } } </code></pre>
    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