I am using Entity Framework in my C# based code. I am running into an unexpected weirdness and am looking for suggestions.
Case 1, 2, 3, 4...
Projects:
RivWorks
I stumbled upon this and found a different fix. I was using var query = context.Contacts.Where(c => c.FullNameReverse == "TingTong");
and getting the mentioned error. The mistake was I was using the method FullNameReverse()
as property FullNameReverse
. Missed the ()!!!
I was having a similar problem binding columns to a Telerik MVC Grid. I had an Id property on my ViewModel class. (Inspired by Chris's answer above) I renamed it to XxxId and the problem went away. I seem to recall something about MVC doing something special for Id properties.
I had this problem in a slightly different version.
Should you call a (static) method from inside your lambda, check its return type. If the return type should be an IEnumerable (which often is true when using lambdas) but you return object, obviously you have a problem.
For those interested in the outcome:
I was missing a simple Using statement at the head of my code.
using System.Linq;
This fixed it right up.
In my case it was missing
using System.Data.Entity;
Thread's a bit old, but I only just encountered this, and nothing on the 'net was the answer. One site mentioned what lead to the answer, which was a data type issue, but sadly I can't find it again, so I'm posting my solution here. Maybe some future searcher will derive benefit from it.
Original: IQueryable test = from r in Records where r.Record_ID == 100 select r;
where Records is an IQueryable resulting from a prior LINQ expresson.
The fix is to cast Records: (IQueryable<record>)Records in the expression. Having found it, it makes perfect sense. Records isn't typed so the LINQ has no clue if r.Record_ID is valid. The confusion is the error message, which appears all over the 'net in dozens of places, in nearly every case the solution being one of the two using clauses missing. The one or two I found that were not an using issue, they didn't bother to post what fixed it.
Hope this helps...