【发布时间】:2021-08-28 23:07:48
【问题描述】:
我想从 sqlite 数据库中获取项目(数据库中大约有 6,000 个项目) 有些物品是重复的因此,我想在获得物品时删除此重复信息
我使用了以下代码
public async static Task<List<myModel>> GetAllItems()
{
using var db = new dbContext();
var query =
from item in db.myTable.GroupBy(x => x.Id).Select(x => x.First())
select new myModel
{
Id = item.Id,
Name = item.Name,
...
};
return await query.ToListAsync();
}
但我收到以下错误
System.InvalidOperationException: 'The LINQ expression 'GroupByShaperExpression:
KeySelector: m.Id,
ElementSelector:EntityShaperExpression:
EntityType: myTable
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.First()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'
【问题讨论】:
-
请提供EF Core版本。
-
@IvanStoev Microsoft.EntityFrameworkCore.Sqlite 5.0.6