LINQ到实体无法识别方法'布尔包含[小数] [英] LINQ to Entities does not recognize the method 'Boolean Contains[Decimal]
本文介绍了LINQ到实体无法识别方法'布尔包含[小数]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的LINQ,所以我在这里混淆pretty。我有一个数据库,并尝试以下code运行。
I am new to LINQ, so I am pretty confused here. I have a database and try to run following code.
IQueryable<decimal> location_ids = (from m in _db.Admins
where m.UserId.Equals("c5d3dc0e-81e6-4d6b-a9c3-faa802e10b7d")
select m.LocationId);
if (!location_ids.Contains(new Decimal(conf.umisteni.Budova.ID)))
在if语句,我得到一个错误,我不明白,我也不知道,如何解决这个问题:
On the if statement I get an error I don't understand, nor do I know, how to solve it:
System.NotSupportedException: LINQ to Entities does not recognize the method 'Boolean Contains[Decimal](System.Linq.IQueryable`1[System.Decimal], System.Decimal)' method, and this method cannot be translated into a store expression.
at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
任何想法?
推荐答案
使用LINQ到对象的IEnumerable将让你使用包含(十进制)上查询的结果。
Using Linq-to-Objects IEnumerable will let you use Contains(Decimal) on the result of the query.
IEnumerable<decimal> location_ids = (from m in _db.Admins
where m.UserId.Equals("c5d3dc0e-81e6-4d6b-a9c3-faa802e10b7d")
select m.LocationId);
但是,为什么不只是扩大where子句:
However, why not just expand the where clause:
IEnumerable<decimal> location_ids = (from m in _db.Admins
where m.UserId.Equals("c5d3dc0e-81e6-4d6b-a9c3-faa802e10b7d") && (m.LocationId == conf.umisteni.Budova.ID)
select m.LocationId);
if (!location_ids.Any())
这篇关于LINQ到实体无法识别方法'布尔包含[小数]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文