我正在使用C#和.NET Framework 4.5.1使用Entity Framework 6.1.3从SQL Server数据库中检索数据.
我有这个:
codes = codesRepo.SearchFor(predicate)
.Select(c => new Tuple<string, byte>(c.Id, c.Flag))
.ToList();
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到此消息:
LINQ to Entities中仅支持无参数构造函数和初始值设定项.
我不知道我是如何创建元组的,因为我发现的所有例子大多都是这样的.
我试过这个:
codes = codesRepo.SearchFor(predicate)
.Select(c => Tuple.Create(c.Id, c.Flag))
.ToList();
Run Code Online (Sandbox Code Playgroud)
并得到此错误:
LINQ to Entities无法识别方法'System.Tuple`2 [System.String,System.Byte] Create [String,Byte](System.String,Byte)'方法,并且此方法无法转换为商店表达式.
问题出在哪儿?
我需要从一个需要在LINQ查询中运行的函数中获取结果.这个结果绑定到网格但在运行时遇到这个错误:
LINQ to Entities无法识别方法'System.String GetName(System.Type,System.Object)'方法,并且此方法无法转换为商店表达式.
这是我的代码:
public IQueryable GetForRah_CapacityList(XQueryParam param)
{
var result = (from x in Data()
select new
{
Rah_CapacityId = x.Rah_CapacityId,
Rah_CapacityName = x.Rah_CapacityName,
Rah_St = Enum.GetName(typeof(Domain.Enums.CapacityState), x.Rah_St),
Rah_LinesId = x.Rah_LinesId
}).OrderByDescending(o => new { o.Rah_CapacityId });
return result;
}
Run Code Online (Sandbox Code Playgroud)