【发布时间】:2016-06-18 12:37:01
【问题描述】:
如何编写 LINQ 查询以返回 Bool 值?
到目前为止我的代码,
public class AddNewRow
{
public static Func<DatabaseDataContext, DateTime, int, Staff_Time_TBL>
GetNewRowMissingData =
CompiledQuery.Compile((DatabaseDataContext db, DateTime dDate, int staffNo) =>
db.Staff_Time_TBLs.Any(a => a.Date_Data == dDate && a.Staff_No == staffNo));
}
也试过了,
public class AddNewRow
{
public static Func<DatabaseDataContext, DateTime, int, Staff_Time_TBL>
GetNewRowMissingData =
CompiledQuery.Compile((DatabaseDataContext db, DateTime dDate, int staffNo) =>
db.Staff_Time_TBLs.Where(a => a.Date_Data == dDate && a.Staff_No == staffNo).Any());
}
因此,如果两个条件都满足,则返回 true。
我尝试过的任何其他代码都会使帖子变得混乱。
研究链接,
另外,我有本书 Pro C# 5.0 and the .NET 4.5 Framework (Expert's Voice in .NET) 参考。
【问题讨论】:
-
你到底在问什么?第一个 LINQ 查询“更好”/更惯用,
-
@ChrisF,让编译后的查询返回一个布尔值?