Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
491 views
in Technique[技术] by (71.8m points)

c# - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...