无法识别查询源
Query Source could not be identified
我正在尝试使用 group by:
从 Posting
类型的列表中生成 Transaction
类型的列表
var transactions = postings
.GroupBy(p => p.TransactionId, (key, g) => new { TransactionId = key, Postings = g })
.Select(x => new Transaction
{
TransactionId = x.TransactionId,
PostingCount = x.Postings.Count(),
TransactionState = x.Postings.First().PostingState,
CreateDate = x.Postings.First().CreateDate,
CreateUser = x.Postings.First().CreateUser
});
但是我遇到了这个错误:
Query Source could not be identified: ItemName = _3, ItemType = Crm.Library.Model.Posting, Expression = from Posting _3 in Convert([p])
当我对 x.Postings
[First()
执行任何操作时会发生此错误。
关于如何获得所需结果的任何想法?
我通过在使用 GroupBy
之前将 Posting
的列表转换为 IEnumerable
解决了这个问题
使用 IQueryable
的问题将被转换为 SQL,这将无法理解我的 .net 方法。自定义类型的投影是查询的一部分,必须进行硬编码。
我现在的代码是:
var transactions = postings.AsEnumerable().GroupBy(p => p.TransactionId, (key, g) => new { TransactionId = key, Postings = g })
.Select(x => new Transaction
{
TransactionId = x.TransactionId,
PostingCount = x.Postings.Count(),
TransactionState = x.Postings.First().PostingState,
CreateDate = x.Postings.First().CreateDate,
CreateUser = x.Postings.First().CreateUser
});
我正在尝试使用 group by:
从Posting
类型的列表中生成 Transaction
类型的列表
var transactions = postings
.GroupBy(p => p.TransactionId, (key, g) => new { TransactionId = key, Postings = g })
.Select(x => new Transaction
{
TransactionId = x.TransactionId,
PostingCount = x.Postings.Count(),
TransactionState = x.Postings.First().PostingState,
CreateDate = x.Postings.First().CreateDate,
CreateUser = x.Postings.First().CreateUser
});
但是我遇到了这个错误:
Query Source could not be identified: ItemName = _3, ItemType = Crm.Library.Model.Posting, Expression = from Posting _3 in Convert([p])
当我对 x.Postings
[First()
执行任何操作时会发生此错误。
关于如何获得所需结果的任何想法?
我通过在使用 GroupBy
之前将 Posting
的列表转换为 IEnumerable
解决了这个问题
使用 IQueryable
的问题将被转换为 SQL,这将无法理解我的 .net 方法。自定义类型的投影是查询的一部分,必须进行硬编码。
我现在的代码是:
var transactions = postings.AsEnumerable().GroupBy(p => p.TransactionId, (key, g) => new { TransactionId = key, Postings = g })
.Select(x => new Transaction
{
TransactionId = x.TransactionId,
PostingCount = x.Postings.Count(),
TransactionState = x.Postings.First().PostingState,
CreateDate = x.Postings.First().CreateDate,
CreateUser = x.Postings.First().CreateUser
});