【发布时间】:2018-09-29 20:21:47
【问题描述】:
我有一个通用存储库,其中包含这样的方法
public async Task<List<TEntity>> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, Expression<Func<TEntity, TEntity>> select=null)
{
IQueryable<TEntity> query = dbSet;
if (filter != null)
{
query = query.Where(filter);
}
if (select != null)
{
query = query.Select(select);
}
if (orderBy != null)
{
return await orderBy(query).ToListAsync();
}
else
{
return await query.ToListAsync();
}
}
并像这样在我的存储库中使用它:
return await _unitOfWork.GetRepository<DeliveryMethod>().
Get(q => q.DeliveryMethodLoclizes.Any(x => x.LanguageId == language), null,
s => new DeliveryMethod()
{
Id = s.Id,
IsActive = s.IsActive,
IsDel = s.IsDel,
DeliveryMethodLoclizes = s.DeliveryMethodLoclizes.Where(x => x.LanguageId == language)
.Select(w => new DeliveryMethodLocalize()
{
Id = w.Id,
LanguageId = w.LanguageId,
Title = w.Title,
Description = w.Description
})
.ToList()
});
但是当我运行我的代码时,将这个错误返回给我
The entity or complex type 'Domain.DeliveryMethod' cannot be constructed in a LINQ to Entities query.
请帮我解决这个错误
【问题讨论】: