[英]EF Core - Select all columns using EF.Functions.Like
I'm searching a large view on a SQL Server database using EF Core 3.1.4 (table names obfuscated).我正在使用 EF Core 3.1.4(表名混淆)搜索 SQL 服务器数据库的大视图。
var query = searchModel.SearchQuery.ToUpper();
list = list.Where(s => EF.Functions.Like(s.name0.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name1.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name2.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name3.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name4.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name5.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name6.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name7.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name8.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name9.ToUpper(), $"%{query}%")
|| EF.Functions.Like(s.name10.ToUpper(), $"%{query}%"));
Is there a way to just select all columns instead of adding an or operator in the Where
condition for each column?有没有办法只 select 所有列,而不是在每列的Where
条件中添加一个或运算符?
You may be able to read the schema of the DB through the Entity Framework, using this answer as a starting point.您可以使用此答案作为起点,通过实体框架读取数据库的架构。 Once you have a list of the column names, you could write a static or extension method IsLikeAColumn
, used like Where(s => IsLikeAColumn(s))
, looking something like:一旦你有一个列名列表,你可以编写一个 static 或扩展方法IsLikeAColumn
,像Where(s => IsLikeAColumn(s))
一样使用,看起来像:
bool match = false;
foreach (string columnName in columnNames)
{
match |= EF.Functions.Like(columnName, $"%{query}%");
}
return match;
No, Its not possible at all and even in SQL server also its not possible.不,这根本不可能,甚至在 SQL 服务器中也是不可能的。 Even in C# If
and While
also you can not do this.即使在 C# If
和While
你也不能这样做。 You should have multiple conditions with comparison operators比较运算符应该有多个条件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.