使用.include(),. where(),. select()进行LINQ查询

时间:2014-07-22 10:38:23

标签: c# linq

我有这样的查询:

var rrx = (from camp in db.Campus
                     join camproom in db.CampusRooms
                           on camp.Id equals camproom.CampusId
                      where (camproom.CampusId == 1) && (camp.BranchId == 10) && (camproom.Status == 0)
                     select new CampusCampusRoom { CampName = camp.Name, CampusRoomNo = camproom.RoomNo, CampusClassCapacity = camproom.ClassCapacity, CampusExamCapacity = camproom.ExamCapacity  }).ToList();

如何使用.include().where().select()条款执行此查询?

1 个答案:

答案 0 :(得分:0)

这是一个易于使用的过滤投影示例。这应该为您提供一个很好的示例,说明您要对查询执行的操作。:

var customersWithRecentReservations = 
    from c in context.Contacts.OfType<Customer>()
    where c.FirstName == p_firstName && c.LastName == p_lastName 
    select new {Customer = c, Reservations = c.Reservations.Where(r => r.ReservationDate >= p_reservationDate)};

var customers = customersWithRecentReservations.AsEnumerable().Select(p => p.Customer);

尝试并根据您的情况调整此代码,或者如果您需要进一步的帮助,请告诉我们;)