实体框架 - 无法将 lambda 表达式转换为类型“字符串",因为它不是委托类型 [英] Entity Framework - Cannot convert lambda expression to type 'string' because it is not a delegate type
问题描述
我在基于 C# 的代码中使用实体框架.我遇到了意想不到的怪事,正在寻求建议.
I am using Entity Framework in my C# based code. I am running into an unexpected weirdness and am looking for suggestions.
案例 1、2、3、4...项目:
RivWorks.dll
RivWorks.Service.dll
RivWorks.Alpha.dll
Case 1, 2, 3, 4...
Projects:
RivWorks.dll
RivWorks.Service.dll
RivWorks.Alpha.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();
}
等
案例怪异":
RivWorks.Web.Service.dll(WCF 项目)
包含与其他项目相同的引用.
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();
...
}
我收到此编译时错误(在我的编辑器中突出显示了where"一词):
无法将 lambda 表达式转换为类型字符串",因为它不是委托类型
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?
推荐答案
对于那些对结果感兴趣的人:
我在代码的开头缺少一个简单的 Using 语句.
For those interested in the outcome:
I was missing a simple Using statement at the head of my code.
using System.Linq;
这个问题就解决了.
这篇关于实体框架 - 无法将 lambda 表达式转换为类型“字符串",因为它不是委托类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!