【问题标题】:RIA Servcies Filter Out Included EntitiesRIA 服务过滤掉包含的实体
【发布时间】:2013-10-18 19:08:48
【问题描述】:

Below 返回建筑物中的所有人以及他们所有的计算机,这很有效。

我想将其更改为仅包括 Active == 1 的计算机和 ActivityTypeId == 5 的 ActivityLogs。但如果它们都没有,我仍然希望此人返回。

  public IQueryable<Person> GetPeople(int BuildingId)
        {
         return this.ObjectContext.People
                .Include("Computers")
                .Include("ActivityLog")
                .Where(p => p.buildingId == BuildingId && !p.migrated)
                .OrderBy(p => p.name);
         }

【问题讨论】:

    标签: linq entity-framework silverlight wcf-ria-services ria


    【解决方案1】:

    不幸的是,使用Include 语法是不可能的。作为替代方案,您可以像这样单独选择每个实体:

    var queryWithAllData = this.ObjectContext
                               .People
                               .Select(p => new
                               {
                                   Person = p,
                                   Computers = p.Computers.Where(c => c.Active == 1),
                                   ActivityLogs = p.ActivityLog.Where(a => a.ActivityTypeId == 5)
                               });
    
    // Do what you need with the records now that you have all the data.
    

    【讨论】:

    • 我如何从 RIA 服务中获取此信息?
    • 我建议您开始一个新问题,因为您最初的问题并没有真正提出这个问题,也没有包含有关您的设置和您想要完成的任何细节。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 2011-07-09
    相关资源
    最近更新 更多