Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.dll
RivWorks.Service.dll
RivWorks.Alpha.dll

Samples (all of these work):
RivWorks.Alpha.dll:

public static bool EndNegotitation(long ProductID) {     var product = (from a in _dbFeed.AutoWithImage                     where a.AutoID == ProductID select a).FirstOrDefault(); ... } 

RivWorks.Service.dll

public static RivWorks.Model.NegotiationAutos.AutoWithImage      GetProductById(long productId) {     var myProduct = from a in _dbFeed.AutoWithImage                      where a.AutoID == productId select a;      return myProduct.FirstOrDefault(); } public static List<RivWorks.Model.NegotiationAutos.AutoWithImage>      GetProductByCompany(Guid companyId) {     var myProduct = from a in _dbFeed.AutoWithImage                      where a.CompanyID == companyId select a;      return myProduct.ToList(); } 

etc

Case "weirdness":
RivWorks.Web.Service.dll (WCF project)
Contains the same references as the other projects.

public NegotiateSetup GetSetup(string method, string jsonInput) {     ...     long.TryParse(ProductID, out result);     var product = (from a in _dbFeed.AutoWithImage                     where a.AutoID == result select a).FirstOrDefault();     ... } 

I am getting this compile time error (the word "where" is highlighted in my editor):
Cannot convert lambda expression to type 'string' because it is not a delegate type

Any ideas what would cause this?

like image 390
Keith Barrows Avatar asked Jan 13 '10 16:01

Keith Barrows


2 Answers

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.

like image 60
Keith Barrows Avatar answered Oct 02 '22 07:10

Keith Barrows


In my case it was missing

using System.Data.Entity;

like image 27
Miguel Galante Avatar answered Oct 02 '22 06:10

Miguel Galante