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

本文关键字:LINQ 查询 进行 select 使用 where include | 更新日期: 2023-09-27 18:13:59

我有一个这样的查询:

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()子句执行查询?

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

这是一个易于使用的过滤投影示例。这应该为您提供一个很好的示例,说明您希望如何处理查询。:

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);

试着把这段代码适应你的情况,或者让我知道如果你需要进一步的帮助;)