无法在lambda表达式中转换此查询

时间:2014-04-15 10:53:06

标签: c# lambda

我坚持将此查询转换为lambda Expression。

SELECT        Timesheet_Detail_Id, Date, Proj_Id, Task_Id, Ticket_No, Description, Hours, IsBillable, Billing_Hrs, Link_To, Status_Id, Timesheet_Id, flag, Remarks, EntryDate
FROM         dbo.Timesheet_details
WHERE        (Link_To = 7) OR
             (Link_To =
             (SELECT User_Id FROM dbo.User_Details
             WHERE(Leader_User_Id = 7)))

我的尝试: -

int linkto=Convert.ToInt32(Session["login_user_Id"]);
var list=de.User_Details.Where(y => y.Leader_User_Id==linkto).Select(y => y.User_Id);
lvTimesheet.DataSource = de.TimeSheetDetailViews.Where(x => x.Link_To == linkto || x.Link_To == list).ToList();

我想在Lambda表达式中转换此查询,但我收到如下错误。

错误列表

Error   39  Cannot convert lambda expression to type 'string' because it is not a delegate type D:\Govinda\OfficeProjects\InfosenseTimeSheet\InfoSenseTimeSheet\InfoSenseTimeSheetWeb\ViewMyTimesheetList.aspx.cs   16  64  D:\...\InfoSenseTimeSheetWeb\

Error   40  Delegate 'System.Func<InfosenseTimeSheetModel.TimeSheetDetailView,int,bool>' does not take 1 arguments  D:\Govinda\OfficeProjects\InfosenseTimeSheet\InfoSenseTimeSheet\InfoSenseTimeSheetWeb\ViewMyTimesheetList.aspx.cs   16  64  D:\...\InfoSenseTimeSheetWeb\

Error   41  Operator '==' cannot be applied to operands of type 'decimal' and 'System.Linq.IQueryable<decimal>' D:\Govinda\OfficeProjects\InfosenseTimeSheet\InfoSenseTimeSheet\InfoSenseTimeSheetWeb\ViewMyTimesheetList.aspx.cs   16  92  D:\...\InfoSenseTimeSheetWeb\

注意: -

Sql查询工作正常。

1 个答案:

答案 0 :(得分:2)

我得到了答案

int linkto=Convert.ToInt32(Session["login_user_Id"]);
var list=de.User_Details.Where(y => y.Leader_User_Id==linkto).Select(y => y.User_Id);
lvTimesheet.DataSource = de.TimeSheetDetailViews.Where(x => x.Link_To == linkto || list.Contains(x.Link_To)).ToList();