Silverlight + WCF RIA + how to include a conditional set of child records (not all but a set)
I've got a problem with loading related data via WCF RIA and Entity Framework - please help me - i don't know how to solve it.
I have Room <-- RoomRecords(contains startDate/endDate fields and reference to parent Room) and I have to load RoomRecords where e.g. start date >= 1.07.2010 and endDate <= 15.07.2010. Parent Room should also be included. I'm using [Include] attribute on Room property plus i'm using this approach - 'How to do a Conditional Include' - to retrieve rel开发者_如何学运维ated data.
The problem is that on client side i get Room with ALL roomRecords related (e.g. where start/end date are from past year - this is not what i need - there is will be a lot of records!) but i need to get Rooms with RoomRecords JUST with start/end date that suits by the condition mentioned. What is the way to solve it? Thank you!
Ups!
Seems like I was wrong - everything works fine and conditional loading is working properly... Pardon!
the query:
var res = from room in this.ObjectContext.Rooms
from rr in room.RoomRecords
where
(rr.StartDate >= startDate.Date && rr.StartDate < endDate) ||
(rr.EndDate > startDate.Date && rr.EndDate < endDate) ||
(rr.StartDate < startDate.Date && rr.EndDate >= endDate)
select new {
Room = rr.Room,
rRec = rr
};
var ret = res.AsEnumerable().Select(d => d.Room);
var justRoomRecords = ret.SelectMany(r => r.RoomRecords).ToList(); // just to check
return ret;
精彩评论