当我试图创建一个连接与IEEECollection与DbSet它抛出以下异常,所以我想我可以包括一个属性,然后过滤这个属性,我需要和选择它。
System.InvalidOperationException:'LINQ表达式'DbSet().Join(inner:__p_0,outerKeyToken:y => y.IdToken,innerKeyToken:z => z.IdToken,resultToken:(tokens,userTokens)=> tokens)'无法转换。请以可转换的形式重写查询,或通过插入对' AsEnumerable ',' AsAsyncEnumerable ',' ToList ',' AsEnumerable ',' AsEnumerable ',' ToList ',' AsEnumerable '的调用,或'ToListAsync'。有关详细信息,请参阅https://go.microsoft.com/fwlink/?linkid=2101038。'
public async Task<IEnumerable<TResult>> Join<Tkey, TEntity, VKey, TResult>(IEnumerable<TEntity> collection, Expression<Func<T, Tkey>> outerSelector, Expression<Func<TEntity, Tkey>> innerSelector, Expression<Func<T, TEntity, TResult>> resultSelector)
where TEntity : class, new()
where TResult:class,new()
{
return await Db.Set<T>().Join(collection, outerSelector, innerSelector, resultSelector).ToListAsync();
}
字符串
现在我想使用的查询是这样的
public async Task<IEnumerable<TResult>> Join<Tkey,TIncludeProperty, TEntity, TResult>(IEnumerable<T> collection,Expression<Func<T,TIncludeProperty>> includeClause, Func<T, IEnumerable<T>, bool> whereFilter, Expression<Func<T, TResult>> resultSelector)
where TEntity : class, new()
where TResult :class,new()
where TIncludeProperty: class,new()
{
try
{
return await Db.Set<T>().Include(includeClause).Where(x=>whereFilter(x,collection)).Select(resultSelector).ToListAsync();
}
catch (Exception ex)
{
return Enumerable.Empty<TResult>();
}
}
型
我如何将方法签名上的集合传递给whereFilter?
2条答案
按热度按时间rqmkfv5c1#
解决方案是修复查询并使用where过滤器,同时重载以添加另一个where过滤器
字符串
zpqajqem2#
你可以用这个逻辑,
字符串
。希望这能帮到你