views:

45

answers:

1

Hello everyone!

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 related 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!

+1  A: 

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