LINQ to Entities无法识别方法'Char get_Chars(Int32)',并且该方法无法转换为商店表达式 [英] LINQ to Entities does not recognize the method 'Char get_Chars(Int32)' method, and this method cannot be translated into a store expression
问题描述
我只想从字符串eventTriggers
中选择字段为"1"的记录(看起来像这样:"00100010")
I would like to select only the records that have the field "1" from the string eventTriggers
(that looks something like this : "00100010" )
我已经尝试并成功地进行了1次以上的呼叫..但我怀疑它的效率.基本上,我会想要这样的东西...但是LINQ显然不支持此功能.
(LINQ to Entities does not recognize the method 'Char get_Chars(Int32)' method, and this method cannot be translated into a store expression.
)
I've tried and succesfully done so with more than 1 calls .. but i doubt its efficient. Basically I would want something like this ... but apprently LINQ does not support this.
(LINQ to Entities does not recognize the method 'Char get_Chars(Int32)' method, and this method cannot be translated into a store expression.
)
using (var service = new dB.Business.Service.BaseBusinessService<memo>())
{
List<memo> result = service.Repository.GetQuery().Where(p => p.ID == ID && p.eventTriggers[index] == '1').ToList();
}
是否有正确解决方案的提示?谢谢 !
Any hints towards the correct solution ? Thank you !
推荐答案
EF无法将char数组操作转换为有效查询.怎么样
EF can't convert the char array operation into a valid query. How about
IEnumerable<Memo> memos
using (var service = new dB.Business.Service.BaseBusinessService<Memo>())
{
memos = service.Repository.GetQuery()
.Where(p => p.ID == ID).AsEnumerable();
}
var result = memos.Where(m => m.eventTriggers[index] == '1').ToList();
这会在本地获取所有具有匹配ID的备忘录,然后在eventTriggers数组上进行过滤.
This gets all the memos with a matching ID locally then filters on the eventTriggers array.
或者,您可以将eventTriggers转换为数值并使用位掩码,这可能是一个更快的查询.
Alternatively you could convert eventTriggers into a numeric value and use a bit mask, this would probably be a much faster query.
Linq看起来像这样
Linq looking like this,
using (var service = new dB.Business.Service.BaseBusinessService<Memo>())
{
result = service.Repository.GetQuery()
.Where(p =>
p.ID == ID
&&
m.eventTriggers & mask != 0).ToList();
}
这篇关于LINQ to Entities无法识别方法'Char get_Chars(Int32)',并且该方法无法转换为商店表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!