Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can have one main model include every fields and sub models you want and every time you select different sub set of query, you using this main model. Example mine generic function :-</p> <pre><code>public List&lt;T&gt; IncludeMultipleWithWhere(Expression&lt;Func&lt;T, bool&gt;&gt; predicate, params Expression&lt;Func&lt;T, object&gt;&gt;[] includes, Expression&lt;Func&lt;T, T&gt;&gt; select=null) { IQueryable&lt;T&gt; itemWithIncludes = dbContext.Set&lt;T&gt;() as IQueryable&lt;T&gt;; try { if (select != null) { itemWithIncludes = includes.Aggregate(itemWithIncludes, (current, include) =&gt; current.Include(include)).Where(predicate).Select(select); } else { return dbContext.Set&lt;T&gt;().Where(predicate); }//end if-else } catch (Exception ex) { Logger.Error("Error", ex); } finally { } return itemWithIncludes.ToList(); } </code></pre> <p>Your calling function can pass in the main model as T , and different select expression. example:- </p> <pre><code>Expression&lt;Func&lt;CRM_RelationTbl, bool&gt;&gt; whereCond1 = (x) =&gt; x.intCRM == 0; Expression&lt;Func&lt;CRM_RelationTbl, object&gt;&gt;[] includeMulti = { n =&gt; n.promotion.partners, n =&gt; n.program, n =&gt; n.campaign }; System.Linq.Expressions.Expression&lt;Func&lt;CRM_RelationTbl,CRM_RelationTbl&gt;&gt; select = u =&gt; new CRM_RelationTbl { intCat = u.intCat, intCatRef=u.intCatRef, varCatRef = u.varCatRef, nvarDesc =u.nvarDesc }; serviceRelation.IncludeMultipleWithWhere(whereCond1, includeMulti,select) </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.
    1. VO
      singulars
      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