Entity Framework - Cannot convert lambda expression to type 'string' because it is not a delegate type

后端 未结 15 2300
再見小時候
再見小時候 2020-11-30 09:18

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

15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 10:03

    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)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...

提交回复
热议问题