你好,我遇到了错误
Cannot implicitly convert type 'System.Linq.IQueryable<Database.Table>' to 'bool'
来自这段代码
foreach (var file in files)
{
if (context.SomeTables.Where(p => p.FileName == System.IO.Path.GetFileName(file)))
{
//Do Something //above I am trying to compare if the filename in the db table
//is equal to the GetFileName being passed in but it throwing
//the error
}
最佳答案
context.SomeTables.Where(p => p.FileName == System.IO.Path.GetFileName(file))
返回一个IQueryable
,而不是一个bool
。你需要一些返回 bool
的东西,比如
context.SomeTables.Any(p => p.FileName == System.IO.Path.GetFileName(file))
作为 if
语句的条件。
关于c# - 无法将类型 'System.Linq.IQueryable<Database.Table>' 隐式转换为 'bool',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17094894/