【问题标题】:How to form a Method based syntax in Linq Entity Framework如何在 Linq 实体框架中形成基于方法的语法
【发布时间】:2014-01-10 14:47:57
【问题描述】:

我在 ASP.NET Web 应用程序中使用实体框架我已经形成了一个 linq 查询,以使用基于查询的语法获取该位置的员工的报价列表。查询如下。

主 Linq 查询

using (var emp = new EmployeeEntities())
            {
                return
                    (
                        from p in emp.Employees
                        join pl in emp.EmployeeLocations on p.Id equals pl.EmployeeId
                        join l in emp.OfferLocations on pl.Id equals l.EmployeeLocationId
                        join po in emp.EmployeeOffers on l.EmployeeOfferId equals po.Id
                        where p.Id == employeeId && po.ParentId == SpecialGroupId && po.Id == offerid
                        select po
                    ).ToList().AsReadOnly();
            }

我想知道如何通过使用来形成基于方法的语法

在哪里

包括

像下面的例子

Linq 查询示例

 return emp.EmployeeLocations.Include("OfferLocations.EmployeeOffer.Category").Include("Employee").Where(pl => pl.Id == locationId).ToList<EmployeeLocation>();

谁能帮我形成基于方法的查询。谢谢

【问题讨论】:

  • 你可以accept回答否?

标签: asp.net linq entity-framework


【解决方案1】:

要实现您的查询,您不能这样做,

using (var emp = new EmployeeEntities())
{
    return emp.Where(p => p.Id == employeeId)
        .SelectMany(p => p.EmployeeOffers)
        .Where(po => po.ParentId == SpecialGroupId && po.Id == offerid)
        .ToList()
        .AsReadOnly();
}

【讨论】:

  • [link]谢谢[/link]
【解决方案2】:

我找到答案感谢所有帮助回复的人

 using (var emp = new EmployeeEntities())
        {
          var newres = intreat.EmployeeOffers.Where(po => po.OfferLocations.Where(ol => ol.EmployeeLocation.EmployeeId == empId).Any()).Where(pof => pof.ParentId == parentid && pof.Id != empoffer).ToList<EmployeeOffer>();

        }

【讨论】:

    猜你喜欢
    • 2017-07-26
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2014-02-03
    • 1970-01-01
    相关资源
    最近更新 更多