当我直接运行sql查询时,我必须解决以下问题:
SELECT [hostname]
FROM [ComputerImport]
where LOWER(SUBSTRING (computerimport.hostname, 1, 2)) in ('DE', 'FR') AND computerimport.hostname LIKE '%'
但当我试着离开c#我没有得到任何结果
string searchString = ""
List<string> allowedStatus = new List<string>();
allowedStatus.Add("de");
string sqlquery = "SELECT computerimport.hostname FROM ComputerImport WHERE LOWER(SUBSTRING (computerimport.hostname, 1, 2)) in ({1}) AND (computerimport.hostname LIKE '%' + {0} + '%') ";
_context.OverviewQueries.FromSqlRaw(sqlquery, searchString, string.Join(",", allowedStatus.Select(s => "'" + s + "'").ToArray()));
我也试过:
string.Join(",", allowedStatus.Select(s => "'" + s + "'")
string.Join(",", allowedStatus)
string.Join(",", allowedStatus)ToArray()
有效的方法是:
_context.OverviewQueries.FromSqlRaw(sqlquery, searchString, "DE");
你知道我错过了什么吗?
1条答案
按热度按时间e5njpo681#
您可以使用基本的linq,fromsqlraw更适合于使用表值函数等。