LINQ to Entities不能识别方法'System.Collections.Generic.Dictio
本文关键字:System Collections Generic Dictio Entities to 不能 识别 方法 LINQ | 更新日期: 2023-09-27 18:05:26
我有这个运行时错误异常
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.
我尽我所能去修理它,但没有用。我想从列表中出现的异常是否有人可以帮助我修复它
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;
}
您正在尝试将。net库函数嵌入到EF查询中。由于它不能翻译成SQL,所以不支持此操作。
你必须重写你的查询,不使用。todictionary()。
这种特殊情况可能并不难。如果投影ToDictionary()是必要的,请重新访问。
可以安全地编写SQL可翻译投影.Select( new { anyName: <expression>, otherName: <otherExpression>, etc })