Help with Linq and Generics
Posted
by
Jonathan
on Stack Overflow
See other posts from Stack Overflow
or by Jonathan
Published on 2010-12-28T13:37:19Z
Indexed on
2010/12/28
13:54 UTC
Read the original article
Hit count: 223
Hi to all.
I'm triying to make a function that add a 'where' clause to a query based in a property and a value. This is a very simplefied version of my function.
Private Function simplified(ByVal query As IQueryable(Of T), ByVal PValue As Long, ByVal p As PropertyInfo) As ObjectQuery(Of T)
query = query.Where(Function(c) DirectCast(p.GetValue(c, Nothing), Long) = PValue)
Dim t = query.ToList 'this line is only for testing, and here is the error raise
Return query
End Function
The error message is: LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression.
Looks like a can't use GetValue inside a linq query. Can I achieve this in other way?
Post your answer in C#/VB. Chose the one that make you feel more confortable.
Thanks
© Stack Overflow or respective owner