【问题标题】:Linq to entities where condition not workingLinq 到条件不起作用的实体
【发布时间】:2014-03-31 10:23:55
【问题描述】:
var records = (from m in ctx.myData
               from StatusReport in ctx.ReportStatusDetails
               where (m.UserId == user.UserId && 
                      StatusReport.StatusId == 1 &&
                      ctx.Report.Any(r => r.ReportDate.Month == SqlFunctions.GetDate().Value.Month &&
                                          r.ReportDate.Year == SqlFunctions.GetDate().Value.Year))
               select new
               {
                   m.Id,
                   m.Company.CompanyName,
                   m.UserId,
                   m.aspnet_Membership.aspnet_Users.UserName,
                   m.aspnet_Membership.Email
               })
               .Distinct()
               .ToList();

where 条件StatusReport.StatusId == 1 不起作用。查询返回StatusReport.StatusId 不等于1 的偶数行。

为什么会忽略这个条件?

【问题讨论】:

    标签: entity-framework entity-framework-4 linq-to-entities


    【解决方案1】:

    因为您没有与 m 加入/关联 StatusReport。结果只包含m。见例子http://msdn.microsoft.com/en-us/library/bb311040.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2010-11-08
      相关资源
      最近更新 更多