Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating Union fail with Entity framework
    primarykey
    data
    text
    <p>I want to union two list in entity framework. In one of the union part, I have a collection and in the other one, the collection is empty. I'm trying to put the collection to empty but it doesn't work...</p> <pre><code>var query = Context.Assignments.AsQueryable(); var workItemQuery = Context.WorkItems.AsQueryable(); var assigments = query.Select(o =&gt; new WorkItemAssignment() { EndDate = o.WorkItem.EndDate, StartDate = o.WorkItem.StartDate, IsExternal = o.Resource.IsExternalEmp ? Resources.External : Resources.Internal, ResourceAssignedName = o.Resource.FirstName + " " + o.Resource.LastName, RoleName = o.Role.Name, Specialties = o.AssignmentSpecialties.Select(a =&gt; a.Specialty.Name), WorkItemName = o.WorkItem.Name, WorkItemOwner = o.WorkItem.OwnerResource.FirstName + " " + o.WorkItem.OwnerResource.LastName, WorkItemStatus = o.WorkItem.WorkItemStatus.Name, Days = o.Days.Value, Percentage = o.Percentage.Value, RequestId = o.WorkRequestAllocationId != null &amp;&amp; o.WorkRequestAllocationId != Guid.Empty ? o.WorkRequestAllocation.WorkRequest.RequestId : (int?) null }); var workItemAssignments = workItemQuery.Select(o =&gt; new WorkItemAssignment() { EndDate = o.EndDate, StartDate = o.StartDate, IsExternal = "N/A", ResourceAssignedName = "N/A", RoleName = "N/A", RoleProficiency = "N/A", Specialties = Enumerable.Empty&lt;string&gt;().AsQueryable(), //DO NOT WORK !!! WorkItemName = o.Name, WorkItemOwner = o.OwnerResource.FirstName + " " + o.OwnerResource.LastName, WorkItemStatus = o.WorkItemStatus.Name, Days = null, Percentage = null, RequestId = null }); return assigments.Union(workItemAssignments); </code></pre> <p>error message:</p> <blockquote> <p>LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1[System.String] EmptyString' method, and this method cannot be translated into a store expression.</p> </blockquote> <p>When I remove the properties "Specialities" from my 2 queries, it works...</p> <p>EDIT:</p> <p>Because of the first answer, I want to clarify that I really need to stay in the entity context to keep my <code>IQueryable</code> without having my list materialize. My Kendo grid is doing some filtering / paging, and I want to send it a <code>IQueryable</code>.</p> <p>UPDATE 2:</p> <p>After using the solution of @Moho, It was only missing an <code>IEqualityComparer</code> that removed my collection from being compared between the 2 queries.</p> <pre><code>return assigments.Union(workItemAssignments ,assignmentEqualityComparer); </code></pre>
    singulars
    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.
 

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