我正在使用C#和.NET Framework 4.5.1使用Entity Framework 6.1.3从SQL Server数据库检索数据。在Linq Select中创建元组
我有这样的:
codes = codesRepo.SearchFor(predicate)
.Select(c => new Tuple<string, byte>(c.Id, c.Flag))
.ToList();
当我运行它,我得到这个消息:
Only parameterless constructors and initializers are supported in LINQ to Entities.
我不知道我怎么要创建元组,因为所有的例子是我发现大多是这样的。
我已经试过这样:
codes = codesRepo.SearchFor(predicate)
.Select(c => Tuple.Create(c.Id, c.Flag))
.ToList();
而得到这个错误:
LINQ to Entities does not recognize the method 'System.Tuple`2[System.String,System.Byte] Create[String,Byte](System.String, Byte)' method, and this method cannot be translated into a store expression.
问题出在哪里?
看起来你需要创建一个强类型的对象。但是,是的,很好的问题; upvoted。 – frenchie