银光+ WCF RIA +如何包含一组条件子记录(不是全部,而是一组)

发布于 2024-09-10 09:42:59 字数 545 浏览 0 评论 0原文

我在通过 WCF RIA 和实体框架加载相关数据时遇到问题 - 请帮助我 - 我不知道如何解决它。

我有 Room <-- RoomRecords(包含 startDate/endDate 字段和对父 Room 的引用),并且我必须加载 RoomRecords,其中例如开始日期 >= 1.07.2010 和 endDate <= 15.07.2010。家长室也应包括在内。我在 Room 属性上使用 [Include] 属性加上 我正在使用这种方法 - '如何执行条件包含' - 来检索相关数据。

问题是,在客户端,我得到与所有 roomRecords 相关的房间(例如,开始/结束日期是去年的开始/结束日期 - 这不是我需要的 - 将会有很多记录!),但我需要获得与RoomRecords 仅包含符合所提及条件的开始/结束日期。有什么方法可以解决呢?谢谢你!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的年少不轻狂 2024-09-17 09:42:59

UPS!

看来我错了 - 一切正常,条件加载工作正常......请原谅!

查询:

        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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文