[英]LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary`
I have this erun time error exception 我有这个错误的时间错误异常
LINQ to Entities does not recognize the method
'System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.List`1[Project.Model.Value]]
ToDictionary[Value,String,List`1](System.Collections.Generic.IEnumerable`1[Project.Model.Value],
System.Func`2[Project.Model.Value,System.String],
System.Func`2[Project.Model.Value,System.Collections.Generic.List`1[Project.Model.Value]])'
method, and this method cannot be translated into a store expression.
I tried what ever I can to fixed it but no use. 我尽力修复它但没用。 I think the exception coming from list can someone help me to fix it
我认为来自列表的异常可以帮助我解决它
public IEnumerable<ItemManagement> getItemsForFormType(string formType)
{
using (var db = new AthenaContext())
{
List<Value> dropDownListValue = (from val in db.Values
where val.ParentId == (from va in db.Values
where
va.ParentId
== (from value3 in db.Values
where value3.Name == formType
select value3.RecordId).FirstOrDefault()
select va.RecordId).FirstOrDefault()
select val).ToList();
var result = (from value1 in db.Values
where value1.Name == formType
select
new ItemManagement
{
FormType = value1.Name,
RecordID = value1.RecordId,
FormControllerNames =
(from va in db.Values
where va.ParentId == (from value3 in db.Values where value3.Name == formType select value3.RecordId).FirstOrDefault()
select va).ToDictionary(va => va.Name, va => dropDownListValue)
}).ToList();
return result;
}
You are trying to embed a .NET library function to your EF query. 您正在尝试将.NET库函数嵌入到EF查询中。 As it is not translatable to SQL, this is not supported.
因为它不能翻译成SQL,所以不支持。
You must rewrite your query, without using the .ToDictionary(). 您必须重写查询,而不使用.ToDictionary()。
This particular case it may not to hard. 这种特殊情况可能并不难。 Please revisit if the projection ToDictionary() is necessary at all.
如果根本需要投影ToDictionary(),请重新访问。 You can safely write SQL translatable projection by using:
您可以使用以下方法安全地编写SQL可翻译投影:
.Select( new { anyName: <expression>, otherName: <otherExpression>, etc })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.