I’ve got the following code:
Dim query As IQueryable(Of someObject) =
New ObjectQuery(Of someObject)(queryString, db, MergeOption.NoTracking)
.Where(CType(Function(x) x.Publish = True,
Expression(Of Func(Of someObject, Boolean))))
And it gives me an error that says:
Cannot convert expression of type Func(someObject) System.Nullable(Of
Boolean) to type System.Linq.Expressions.Expression(Of
System.Func(someObject, Boolean)).
I have also tried:
.Where(CType(Function(x) x.Publish = True,
Expression(Of Func(Of someObject, Nullable(Of Boolean)))))
which doesn’t work either.
If I don’t have the CType my where comes up with a narrowing conversion error from IQueryable and IEnumerable, so I need that there, but I am not sure how to write that where parameter as an expression to so it can be converted. Any help?
Don’t use casting with
CTypehere – create the expression directly:Expressions need to be created as such. It’s not possible to convert existing
Funcinto an expression.