Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I set custom property of an Entity type in LINQ to Entities query and still return a IQueryable<T>?
    primarykey
    data
    text
    <p>I have a EF4 model where I have Product entity that have one-to-many relation with Task entity (ChildTasks). I have to get some Projects from db based on some user criteria. The Project has one custom property (not associated with any column) named EstimatedProgress where I have to store additional information about Project - computed weighted average progress of each child task. The problem is that finally I can't return an IEnumerable<code>&lt;Project&gt;</code> but <strong>IQueryable<code>&lt;Project&gt;</code></strong>. The code below demonstrates what I want to achieve (I know it does not compile). </p> <pre><code>var q = from p in ObjectContext.ProjectSet.Include("ProjectBase") where p.ProjectBase.IsTemplate == false from ct in p.ProjectBase.ChildTasks where ct.Progress != null &amp;&amp; ct.EstimatedTime != null group ct by ct.prjProjectBase.Project into g select new { Project = g.Key, EstimatedProgress = g.Sum(oo =&gt; oo.Progress.Value * oo.EstimatedTime.Value) / g.Sum(oo =&gt; oo.EstimatedTime.Value), }; var sortedQ = q.OrderByDescending(o =&gt; o.Project.ProjectBase.Status) .ThenBy(o =&gt; o.Project.ProjectBase.Name); // this is where I want to return IQueryable&lt;Project&gt; // where each project has set custom property EstimatedProgress return sortedQ.Select(o =&gt; { o.Project.EstimatedTime = o.EstimatedProgress; return o.Project; }); </code></pre> <p>The question is: Is it possible to do something similiar with EF4 linq query or maybe some of you have a workaround ;) Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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