我收到以下错误,我不确定LINQ查询中的多个条件的语法是否正确。 我的代码到目前为止,
static class MyQuery
{
private static Func<DatabaseDataContext, IQueryable<Staff_Time_TBL>>
queryFor =
CompiledQuery.Compile((DatabaseDataContext db, DateTime dDate) =>
db.Staff_Time_TBLs.Where(a => a.Date_Data == dDate &&
a.Time_Data_1 == null && a.Time_Data_2 == null).FirstOrDefault());
}
DatabaseDataContext
是LINQ to SQL类的名称。Staff_Time_TBL
是从中获取数据的表。这是错误,
错误CS0029无法隐式转换类型&#39; System.Func (Example3.DatabaseDataContext,System.DateTime, Example3.Staff_Time_TBL)&#39;到&#39; System.Func (Example3.DatabaseDataContext, System.Linq.IQueryable(Example3.Staff_Time_TBL))&#39;
我会发布所有尝试以实现此目的,但会使帖子变得混乱。
用这个作为研究来达到这一点。
答案 0 :(得分:1)
您已将字段定义为:
<br/>
其中有equivelant方法签名:
Func<DatabaseDataContext, IQueryable<Staff_Time_TBL>>
但看看你传递的是什么:
public IQueryable<Staff_Time_TBL> SomeMethod(DatabaseDataContext db)
{
...
}
使用equivelant方法:
(DatabaseDataContext db, DateTime dDate) =>
db.Staff_Time_TBLs.Where(a => a.Date_Data == dDate &&
a.Time_Data_1 == null && a.Time_Data_2 == null)
.FirstOrDefault()
这有两个论点,而不是一个。您还在执行public Staff_Time_TBL SomeMethod(DatabaseDataContext db, DateTime dDate)
{
return
db.Staff_Time_TBLs
.Where(a => a.Date_Data == dDate && a.Time_Data_1 == null && a.Time_Data_2 == null)
.FirstOrDefault();
}
,这意味着您正在返回.FirstOrDefault()
- 而不是Staff_Time_TBL
在不知道完全你想要做什么的情况下,你可能应该重新编写该字段:
IQueryable<Staff_Time_TBL>