Cannot implicity convert type System.Linq.Expression<System.Func<Object, bool>> to bool

Karine

actually I have an Expression like this that work very well in the case of 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;
}

I can use the expression like this : _repositoryObject.Where(GetPublic()) and I will get results.

But I cannot use the same expression when I have to do Linq to SQL pattern like this

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

I have this error

Cannot implicity convert type System.Linq.Expression> to bool for Linq to SQL

and I don't know why...

Karine

Jon Skeet

Firstly, I suspect you actually mean you can call it as:

_repositoryObject.Where(GetPublic())

It's important that you call the method to get the expression tree.

Your query expression is being converted into:

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

... which isn't what you're looking for. Basically, query expressions are translated into method calls using lambda expressions. You don't want that in this case, so you shouldn't use a query expression.

If you want to do other things with a query expression, you can always mix and match, e.g.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert IQueryable<T> to Expression<Func<T, bool>>?

From Dev

Is it possible to convert Expression<Func<T, bool>> to Expression<Func<MyType, bool>>?

From Dev

Convert Expression<Func<TModel, TValue>> to Expression<Func<TModel, bool>>

From Dev

How to modify type parameter of Expression<Func<???, bool>>?

From Dev

Cannot convert from 'lambda expression' to 'system.func dynamic object ' MVC3 Razor

From Dev

Cannot implicitly convert type 'bool' to 'system.threading.tasks.task bool'

From Dev

MVC 5 Cannot implicitly convert type 'System.Linq.IQueryable to bool?

From Dev

Cannot convert type 'T' to bool

From Dev

Cannot convert lambda expression to delegate type 'System.Func<char,bool>'

From Dev

Cannot implicitly convert type 'bool?' to 'bool' in a LinQ query?

From Dev

Proper Way To Convert An Expression<Func<Foo, bool>> To Another Expression<Func<Bar, bool>>

From Dev

cannot implicitly convert System.Type to object

From Dev

Cannot convert lambda expression to type 'System.Linq.Expressions.Expression' because it is not a delegate type

From Dev

Cannot convert lambda expression to type 'bool' because it is not a delegate type

From Dev

Cannot assign to immutable expression of type 'Bool?'

From Dev

LINQ - Cannot implicity convert type, An explicit conversion exsist

From Dev

Convert Expression to Expression<Func<T, bool>>

From Dev

Cannot convert lambda expression to delegate type 'System.Func<T,TKey>'

From Dev

"Cannot implicitly convert type 'bool[]' to 'object[]'"

From Dev

Cannot implicitly convert type 'void' to 'System.Collections.Generic.Dictionary<string,bool>

From Dev

Cannot implicity convert type 'object ' to system.collection.arraylist

From Dev

How do I convert Expression<Func<T, object>> to Expression<Func<T, bool>>?

From Dev

Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task'

From Dev

Cannot implicity convert type string to System.Func<string,int,string,string>

From Dev

Cannot convert return expression of type 'Bool' to return type 'Bool'

From Dev

Cannot convert lambda expression to delegate type 'System.Func<T,TKey>'

From Dev

"Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<C3S.Models.Permission>' to 'bool'."

From Dev

Cannot convert System.Collections.Generic.IEnumerable to bool in Linq Lambda expression

From Dev

"Cannot convert from bool to system.collections.generic.list<bool>" In what seems to be good code

Related Related

  1. 1

    How to convert IQueryable<T> to Expression<Func<T, bool>>?

  2. 2

    Is it possible to convert Expression<Func<T, bool>> to Expression<Func<MyType, bool>>?

  3. 3

    Convert Expression<Func<TModel, TValue>> to Expression<Func<TModel, bool>>

  4. 4

    How to modify type parameter of Expression<Func<???, bool>>?

  5. 5

    Cannot convert from 'lambda expression' to 'system.func dynamic object ' MVC3 Razor

  6. 6

    Cannot implicitly convert type 'bool' to 'system.threading.tasks.task bool'

  7. 7

    MVC 5 Cannot implicitly convert type 'System.Linq.IQueryable to bool?

  8. 8

    Cannot convert type 'T' to bool

  9. 9

    Cannot convert lambda expression to delegate type 'System.Func<char,bool>'

  10. 10

    Cannot implicitly convert type 'bool?' to 'bool' in a LinQ query?

  11. 11

    Proper Way To Convert An Expression<Func<Foo, bool>> To Another Expression<Func<Bar, bool>>

  12. 12

    cannot implicitly convert System.Type to object

  13. 13

    Cannot convert lambda expression to type 'System.Linq.Expressions.Expression' because it is not a delegate type

  14. 14

    Cannot convert lambda expression to type 'bool' because it is not a delegate type

  15. 15

    Cannot assign to immutable expression of type 'Bool?'

  16. 16

    LINQ - Cannot implicity convert type, An explicit conversion exsist

  17. 17

    Convert Expression to Expression<Func<T, bool>>

  18. 18

    Cannot convert lambda expression to delegate type 'System.Func<T,TKey>'

  19. 19

    "Cannot implicitly convert type 'bool[]' to 'object[]'"

  20. 20

    Cannot implicitly convert type 'void' to 'System.Collections.Generic.Dictionary<string,bool>

  21. 21

    Cannot implicity convert type 'object ' to system.collection.arraylist

  22. 22

    How do I convert Expression<Func<T, object>> to Expression<Func<T, bool>>?

  23. 23

    Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task'

  24. 24

    Cannot implicity convert type string to System.Func<string,int,string,string>

  25. 25

    Cannot convert return expression of type 'Bool' to return type 'Bool'

  26. 26

    Cannot convert lambda expression to delegate type 'System.Func<T,TKey>'

  27. 27

    "Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<C3S.Models.Permission>' to 'bool'."

  28. 28

    Cannot convert System.Collections.Generic.IEnumerable to bool in Linq Lambda expression

  29. 29

    "Cannot convert from bool to system.collections.generic.list<bool>" In what seems to be good code

HotTag

Archive