【发布时间】:2021-08-08 16:27:50
【问题描述】:
我在移动项目 (.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
过滤器和排序是由数据网格动态构建的,它在带有 Ef 核心 5 的 .Net 5 中工作,但在这里我有 sqllite 并且没有 EF 核心,而 .net 是 3.0。 如何解决这个问题?
【问题讨论】:
-
args.Filter和args.OrderBy是什么?它们的类型是什么,它们包含什么值? -
它们是由数据网格生成的字符串,如下所示: "((Text == null ? \"\" : Text) == null ? \"\" : (Text == null ? \"\" : 文本)).ToLower().Contains(\"sa\".ToLower())"
标签: c# linq xamarin xamarin.forms mobile