Linq to Entities query is not a primitive type

I have this method that I wrote as:

private void GetReceivedInvoiceTasks(User user, List<Task> tasks) { var taskList = from i in _db.Invoices join a in user.Areas on i.AreaId equals a.AreaId where i.Status == InvoiceStatuses.Received select i; } 

Basically, I tried to get all the accounts in the database in the user area that have received status. I don't understand LINQ very well right now.

I get an error:

base {System.SystemException} = {"It is not possible to create a constant value of type 'Models.Area'. Only primitive types (such as Int32, String and Guid ') are supported in this context."}

Can someone explain to me what I'm doing wrong and how to fix it? I can’t understand now what the problem is. If I cross off the join line, that’s fine, but I really need this line to make sure that I only have accounts from user area / areas (they can belong to more than one area). Is there something wrong with this request?

0
linq linq-to-entities entity-framework
Apr 09 2018-12-12T00:
source share
1 answer

Entity does not support merging with collections in memory. You will have to reconnect your request to use the Contains request with a collection of primitives instead.

In addition, EF does not currently support enum values, so you have to compare with an integer value (if InvoiceStatuses.Received not an enum value, ignore this part).

Both fixes together lead to the following query approach, which should produce results equivalent to your connection:

 int statusReceived = (int)InvoiceStatuses.Received; var areaIds = user.Areas.Select(x=> x.AreaId).ToArray(); var taskList = from i in _db.Invoices where i.Status == statusReceived && areaIds.Contains(i.AreaId) select i; 
+4
Apr 09 2018-12-12T00:
source share



All Articles