好吧,我現在有這個如何在LINQ做這個
public IEnumerable<roomvu_User> GetLocationUsers(
long LocationID,
DateTime StartDate,
DateTime EndDate,
int StartRows,
int MaximumRows)
{
using (DataClasses_RoomViewDataContext context = Context)
{
IEnumerable<roomvu_LocationMapping> Mappings =
(from m in context.roomvu_LocationMappings
where (m.LocationID == LocationID
&& (StartDate <= m.EndDate && m.StartDate <= EndDate))
select m).Skip(StartRows).Take(MaximumRows);
List<roomvu_User> Users = new List<roomvu_User>();
foreach (roomvu_LocationMapping Mapping in Mappings)
{
roomvu_User User = (from u in context.roomvu_Users
where (u.ID == Mapping.UserID)
select u).Single();
Users.Add(User);
}
return Users;
}
}
可是,我討厭在foreach位,必須有一個方式在一個單一的LINQ表達式來做到這一點.....
幫助