如何在 Dynamic Linq 中将多个值与 Contain 一起使用。
正常 Linq 的预期:
using System;
using System.Linq;
public class Simple {
public static void Main() {
string[] names = { "Burke", "Laptop", "Computer",
"Mobile", "Ahemed", "Sania",
"Kungada", "David","United","Sinshia" };
string[] vars = {"i","a"};
var query = names.Where(i=> vars.Any(j=>i.Contains(j))).ToList();
Console.WriteLine(query.Count);
}
}
预期 SQL
SELECT * FROM User WHERE (NAME LIKE '%a%'OR NAME LIKE '%b%')
尝试过动态 Linq :
query = query.Where("new[]{\"a\",\"c\"}.Any(i=>i.Contains(it.ProductName))");
返回异常:
No property or field 'ProductName' exists in type 'String'
依赖项:
.NET核心2.2
实体框架核心 2.2.6
System.Linq.Dynamic.Core 1.0.18 ( https://github.com/StefH/System.Linq.Dynamic.Core )
慕尼黑8549860
相关分类