Key*_*dly 2 c# wpf linq-to-sql
您好我收到错误
Cannot implicitly convert type 'System.Linq.IQueryable<Database.Table>' to 'bool'
Run Code Online (Sandbox Code Playgroud)
从这段代码
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
}
Run Code Online (Sandbox Code Playgroud)
Rob*_*vey 14
context.SomeTables.Where(p => p.FileName == System.IO.Path.GetFileName(file))
Run Code Online (Sandbox Code Playgroud)
返回一个IQueryable
,而不是一个bool
.你需要能够返回的东西bool
,比如
context.SomeTables.Any(p => p.FileName == System.IO.Path.GetFileName(file))
Run Code Online (Sandbox Code Playgroud)
作为if
陈述的条件.
请参见
Enumerable.Any方法(IEnumerable)