无法将类型System.Linq.Expression <System.Func <Object,bool >>隐式转换为bool

卡琳

实际上,我有一个像这样的表达式,在Linq to Entity的情况下效果很好

public static Expression<Func<Tender, bool>> GetPublic()
{
    var now = DateTime.Now.GetEasternStandardDateTime();

    return tender => tender.EndDate > DateTime.Now &&
                     tender.IsClosed == false && 
                     tender.IsCancel == false && 
                     tender.PrivacyLevelId == 1;
}

我可以使用这样的表达式:_repositoryObject.Where(GetPublic())我会得到结果。

但是当我必须像这样对SQL模式执行Linq时,我不能使用相同的表达式

var results = from t in Tenders
              where Tender.GetPublic()
              select t;

我有这个错误

无法将类型System.Linq.Expression>隐式转换为bool,以将Linq转换为SQL

我也不知道为什么

卡琳

乔恩·斯基特

首先,我怀疑您实际上是说您可以这样称呼它:

_repositoryObject.Where(GetPublic())

调用该方法以获取表达式树很重要

您的查询表达式将被转换为:

var results = Tenders.Where(t => Tender.GetPublic());

...这不是您想要的。基本上,查询表达式使用lambda表达式转换为方法调用。在这种情况下,您不需要这样做,因此不应使用查询表达式。

如果要使用查询表达式执行其他操作,则可以始终混合使用,例如

var results = from t in Tenders.Where(Tender.GetPublic())
              where t.SomeOtherProperty
              select t.SomethingElse;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

MVC 5无法将类型'System.Linq.IQueryable隐式转换为bool吗?

来自分类Dev

无法将类型'bool'隐式转换为'system.threading.tasks.task bool'

来自分类Dev

无法将类型'void'隐式转换为'System.Collections.Generic.Dictionary <string,bool>

来自分类Dev

无法将类型'bool'隐式转换为'System.Threading.Tasks.Task'

来自分类Dev

无法将lambda表达式转换为委托类型'System.Func <char,bool>'

来自分类Dev

如何将Expression <Func <T,object >>转换为Expression <Func <T,bool >>?

来自分类Dev

“无法将类型'System.Collections.Generic.IEnumerable <C3S.Models.Permission>'隐式转换为'bool'。”

来自分类Dev

“无法将类型'bool []'隐式转换为'object []'”

来自分类Dev

无法将类型'System.Linq.IQueryable'隐式转换为'System.Data.Entity.DbSet'

来自分类Dev

无法将类型System.Linq.IQueryable隐式转换为System Collections.Generic.IEnumerable

来自分类Dev

无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List'

来自分类Dev

无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List

来自分类Dev

是否可以将Expression <Func <T,bool >>转换为Expression <Func <MyType,bool >>?

来自分类Dev

无法将类型System.EventHandler隐式转换为System.EventHandler <object>错误

来自分类Dev

LINQ:无法将类型“ System.Int32”强制转换为类型“ System.Object”

来自分类Dev

LINQ:无法将类型'System.Int32'强制转换为类型'System.Object'

来自分类Dev

无法将类型'System.Linq.IQueryable <char []>'隐式转换为'string []'

来自分类Dev

无法将类型“System.Linq.IQueryable<System.DateTime>”隐式转换为“System.DateTime”

来自分类Dev

将表达式转换为Expression <Func <T,bool >>

来自分类Dev

如何将 BinaryExpression 转换为 Expression<Func<T, bool>>?

来自分类Dev

将Expression <Func <TModel,TValue >>转换为Expression <Func <TModel,bool >>

来自分类Dev

将Expression <Func <TEntity,IEnumerable <TProperty >>> valueSelector,TValue []值转换为Expression <Func <TElement,bool >>

来自分类Dev

无法将类型'System.Linq.IQueryable <Anon>隐式转换为'System.Linq.IQueryable <Report>的显式转换存在,您是否缺少类型转换?

来自分类Dev

无法将类型'System.Linq.IQueryable'隐式转换为'System.Data.Entity.Infrastructure.DbQuery'

来自分类Dev

无法将类型'System.Linq.IQueryable <AnonymousType#1>'隐式转换为'System.Collections.Generic.IEnumerable <SubCateViewModel>'

来自分类Dev

无法将类型System.Collections.Generic.Ienumerable <string>隐式转换为system.Linq.IOrderedEnumerable <AnonymousType#1>

来自分类Dev

无法将类型字符串隐式转换为System.Func <string,int,string,string>

来自分类Dev

无法将类型'bool'隐式转换为'float'

来自分类Dev

无法将类型'ulong'隐式转换为'bool'

Related 相关文章

  1. 1

    MVC 5无法将类型'System.Linq.IQueryable隐式转换为bool吗?

  2. 2

    无法将类型'bool'隐式转换为'system.threading.tasks.task bool'

  3. 3

    无法将类型'void'隐式转换为'System.Collections.Generic.Dictionary <string,bool>

  4. 4

    无法将类型'bool'隐式转换为'System.Threading.Tasks.Task'

  5. 5

    无法将lambda表达式转换为委托类型'System.Func <char,bool>'

  6. 6

    如何将Expression <Func <T,object >>转换为Expression <Func <T,bool >>?

  7. 7

    “无法将类型'System.Collections.Generic.IEnumerable <C3S.Models.Permission>'隐式转换为'bool'。”

  8. 8

    “无法将类型'bool []'隐式转换为'object []'”

  9. 9

    无法将类型'System.Linq.IQueryable'隐式转换为'System.Data.Entity.DbSet'

  10. 10

    无法将类型System.Linq.IQueryable隐式转换为System Collections.Generic.IEnumerable

  11. 11

    无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List'

  12. 12

    无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List

  13. 13

    是否可以将Expression <Func <T,bool >>转换为Expression <Func <MyType,bool >>?

  14. 14

    无法将类型System.EventHandler隐式转换为System.EventHandler <object>错误

  15. 15

    LINQ:无法将类型“ System.Int32”强制转换为类型“ System.Object”

  16. 16

    LINQ:无法将类型'System.Int32'强制转换为类型'System.Object'

  17. 17

    无法将类型'System.Linq.IQueryable <char []>'隐式转换为'string []'

  18. 18

    无法将类型“System.Linq.IQueryable<System.DateTime>”隐式转换为“System.DateTime”

  19. 19

    将表达式转换为Expression <Func <T,bool >>

  20. 20

    如何将 BinaryExpression 转换为 Expression<Func<T, bool>>?

  21. 21

    将Expression <Func <TModel,TValue >>转换为Expression <Func <TModel,bool >>

  22. 22

    将Expression <Func <TEntity,IEnumerable <TProperty >>> valueSelector,TValue []值转换为Expression <Func <TElement,bool >>

  23. 23

    无法将类型'System.Linq.IQueryable <Anon>隐式转换为'System.Linq.IQueryable <Report>的显式转换存在,您是否缺少类型转换?

  24. 24

    无法将类型'System.Linq.IQueryable'隐式转换为'System.Data.Entity.Infrastructure.DbQuery'

  25. 25

    无法将类型'System.Linq.IQueryable <AnonymousType#1>'隐式转换为'System.Collections.Generic.IEnumerable <SubCateViewModel>'

  26. 26

    无法将类型System.Collections.Generic.Ienumerable <string>隐式转换为system.Linq.IOrderedEnumerable <AnonymousType#1>

  27. 27

    无法将类型字符串隐式转换为System.Func <string,int,string,string>

  28. 28

    无法将类型'bool'隐式转换为'float'

  29. 29

    无法将类型'ulong'隐式转换为'bool'

热门标签

归档