LINQ to Entities does not recognize the method ‘System.String Format(System.String, System.Object, System.Object)’

Entity Framework is trying to execute your projection on the SQL side, where there is no equivalent to string.Format. Use AsEnumerable() to force evaluation of that part with Linq to Objects. Based on the previous answer I have given you I would restructure your query like this: int statusReceived = (int)InvoiceStatuses.Received; var areaIds = user.Areas.Select(x=> … Read more

Entity framework linq query Include() multiple children entities

Use extension methods. Replace NameOfContext with the name of your object context. public static class Extensions{ public static IQueryable<Company> CompleteCompanies(this NameOfContext context){ return context.Companies .Include(“Employee.Employee_Car”) .Include(“Employee.Employee_Country”) ; } public static Company CompanyById(this NameOfContext context, int companyID){ return context.Companies .Include(“Employee.Employee_Car”) .Include(“Employee.Employee_Country”) .FirstOrDefault(c => c.Id == companyID) ; } } Then your code becomes Company company = … Read more

How to take the first N items from a generator or list? [duplicate]

Slicing a list top5 = array[:5] To slice a list, there’s a simple syntax: array[start:stop:step] You can omit any parameter. These are all valid: array[start:], array[:stop], array[::step] Slicing a generator import itertools top5 = itertools.islice(my_list, 5) # grab the first five elements You can’t slice a generator directly in Python. itertools.islice() will wrap an object … Read more

Entity Framework: There is already an open DataReader associated with this Command

It is not about closing connection. EF manages connection correctly. My understanding of this problem is that there are multiple data retrieval commands executed on single connection (or single command with multiple selects) while next DataReader is executed before first one has completed the reading. The only way to avoid the exception is to allow … Read more