LINQ to Entities does not recognize the method, and this method cannot be translated into a storage expression

I call some date in my database using the operation of the object frame. but my below code giving this error

LINQ to Entities does not recognize the 'SchoolBreifcase.Compliance get_Item (Int32)' method, and this method cannot be translated into a warehouse expression.

Here is my full code

FinancialCompliance financialCompliance = new FinancialCompliance(); List<Compliance> compliance = null; if (HttpContext.Current.User.IsInRole("SchoolAdmin")) { compliance = datamodel.Compliances.Where(u => u.UserId == userId).OrderBy(c => c.AddedDate).ToList(); } if (HttpContext.Current.User.IsInRole("User")) { compliance = datamodel.Compliances.Where(u => u.VerifierId == userId || u.OwnerId == userId).OrderBy(c => c.AddedDate).ToList(); } if (compliance != null) { for (int i = 1; i < compliance.Count; i++) { financialCompliance = datamodel.FinancialCompliances.Where(f => f.ComplianceId == compliance[i].ComplianceId).SingleOrDefault(); if (compliance.Count == i) { return financialCompliance; } } } return financialCompliance; } 

This line gives this error:

 financialCompliance = datamodel.FinancialCompliances.Where(f => f.ComplianceId == compliance[i].ComplianceId).SingleOrDefault(); 

Cannot perform stream check on stream I found answers on this site for

LINQ to Entities does not recognize method

etc. But it doesn’t help me. So I asked this question. Please do not close this question due to a question already asked.

+6
source share
2 answers

You need to create a variable to reference compliance[i].ComplianceId , and then use it later.

 for (int i = 1; i < compliance.Count; i++) { var complianceId = compliance[i].ComplianceId; financialCompliance = datamodel.FinancialCompliances.Where(f => f.ComplianceId == complianceId ).SingleOrDefault(); if (compliance.Count == i) { return financialCompliance; } } 
+9
source

This is about compliance[i].ComplianceId . First create a variable:

 var id = compliance[i].ComplianceId; financialCompliance = datamodel.FinancialCompliances .Where(f => f.ComplianceId == id).SingleOrDefault(); 
+10
source

All Articles