我有以下 LINQ 语句(stationId 是一个 int 而 version 是一个字节数组):
var foundStation = (from wd in _Context.AssignmentWizardDatas
from station in wd.AssignmentWizardStationDatas
where station.Id == stationId
where station.Version.SequenceEqual(version)
select station).SingleOrDefault();
当上面的代码运行时,我遇到以下错误:
LINQ to Entities does not recognize the method 'Boolean SequenceEqual[Byte](System.Collections.Generic.IEnumerable
1[System.Byte], System.Collections.Generic.IEnumerable
1[System.Byte])' method, and this method cannot be translated into a store expression.
经过一些阅读,我意识到问题是 LINQ 无法将 SequenceEqual 方法调用转换为 SQL 等效方法(我认为无论如何)。有谁知道解决这个问题的解决方案?或者也许可以在尝试将字节数组与 LINQ 查询一起使用时为我指明正确的方向,但我找不到专门与字节数组有关的现有问题。
提前致谢。
编辑 :使用 Jani 的帖子,这是用于解决此错误的最终代码:
//eager execution of the linq query to find the stations
var foundStation = (from wd in _Context.AssignmentWizardDatas
from station in wd.AssignmentWizardStationDatas
where station.Id == stationId
select station).ToList();
//finding the result in memory
var result = (from f in foundStation
where f.Version.SequenceEqual(version)
select f).SingleOrDefault();
最佳答案
//eager execution of the linq query to find the stations
var foundStation = (from wd in _Context.AssignmentWizardDatas
where wd.Id == stationId
select station).ToList();
//finding the result in memory
var result = from f in foundStation
where f.version.SequenceEqual(version)
select f;
关于使用 SequenceEqual 可枚举方法的 LINQ to Entities 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5621598/