在 Linq to Objects 中将字符串作为查询过滤器发送
Send string as Query Filter in Linq to Objects
我在移动项目 (.net core 3.0) 中使用 sqllite,就像我在使用 EF core (.Net 5) 的 Web 项目中所做的那样,我这样写:
InsAndOuts = await context._database.Table<Data.InOut>().ToListAsync();
var InsAndOutsQ = InsAndOuts.AsQueryable();
if (filter)
{
InsAndOutsQ = InsAndOutsQ.Where(args.Filter); //<= This line is the problem
InsAndOutsQ = InsAndOutsQ.Where(td => td.IsIn == isIn || td.IsIn == !isOut)
.Where(td => td.Date >= model.StartDate && td.Date <= model.EndDate);
}
if (sort)
{
InsAndOutsQ = InsAndOutsQ.OrderBy(args.OrderBy); //<= this line also get error
}
我这里不需要效率,因为列表不多,错误是:
Severity Code Description Project File Line Suppression State
Error CS1503 Argument 2: cannot convert from 'string' to 'System.Func<MobileBlazorHybrid.Data.InOut, bool>' MobileBlazorHybrid C:\...\MobileBlazorHybrid\MobileBlazorHybrid\WebUI\Pages\InOut.razor 343 Active
和
Severity Code Description Project File Line Suppression State
Error CS0411 The type arguments for method 'Enumerable.OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. MobileBlazorHybrid C:\...\MobileBlazorHybrid\MobileBlazorHybrid\WebUI\Pages\InOut.razor 351 Active
过滤器和 orderby 由数据网格动态构建,它在具有 Ef 核心 5 的 .Net 5 中工作,但这里我有 sqllite,没有 EF 核心,.net 是 3.0。
如何解决这个问题?
我添加了包 Microsoft.EntityFrameworkCore.Sqlite 并使用了 System.Linq.Dynamic.Core
解决了我的问题。
我在移动项目 (.net core 3.0) 中使用 sqllite,就像我在使用 EF core (.Net 5) 的 Web 项目中所做的那样,我这样写:
InsAndOuts = await context._database.Table<Data.InOut>().ToListAsync();
var InsAndOutsQ = InsAndOuts.AsQueryable();
if (filter)
{
InsAndOutsQ = InsAndOutsQ.Where(args.Filter); //<= This line is the problem
InsAndOutsQ = InsAndOutsQ.Where(td => td.IsIn == isIn || td.IsIn == !isOut)
.Where(td => td.Date >= model.StartDate && td.Date <= model.EndDate);
}
if (sort)
{
InsAndOutsQ = InsAndOutsQ.OrderBy(args.OrderBy); //<= this line also get error
}
我这里不需要效率,因为列表不多,错误是:
Severity Code Description Project File Line Suppression State
Error CS1503 Argument 2: cannot convert from 'string' to 'System.Func<MobileBlazorHybrid.Data.InOut, bool>' MobileBlazorHybrid C:\...\MobileBlazorHybrid\MobileBlazorHybrid\WebUI\Pages\InOut.razor 343 Active
和
Severity Code Description Project File Line Suppression State
Error CS0411 The type arguments for method 'Enumerable.OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. MobileBlazorHybrid C:\...\MobileBlazorHybrid\MobileBlazorHybrid\WebUI\Pages\InOut.razor 351 Active
过滤器和 orderby 由数据网格动态构建,它在具有 Ef 核心 5 的 .Net 5 中工作,但这里我有 sqllite,没有 EF 核心,.net 是 3.0。 如何解决这个问题?
我添加了包 Microsoft.EntityFrameworkCore.Sqlite 并使用了 System.Linq.Dynamic.Core 解决了我的问题。