实体框架6,Include未按预期工作

时间:2013-12-27 03:57:38

标签: entity-framework entity-framework-6

我正在使用带有Entity Framework 6的ASP.NET MVC5 WebAPI。

public PageResult<OrgSchool> GetOrgSchools(ODataQueryOptions<OrgSchool> options)
{
    var results = options.ApplyTo(db.OrgSchools.Include(o => o.Org).Include(c => c.Country).Include(s => s.State).Include(c => c.City));

    return new PageResult<OrgSchool>(
          results as IEnumerable<OrgSchool>,
          Request.GetNextPageLink(),
          Request.GetInlineCount()
       );
}

.Include仅适用于Org&amp; CityCountry&amp; State返回{$ ref:5}&amp; {$ REF:4}

所有列都是外键,参考表中有相关​​的行。

我可以做些什么,以便所有直接关系数据也包含在响应中?

我尝试使用

db.Configuration.LazyLoadingEnabled = false, 

但没有效果。

JSON响应(仅部分输出)。

输出是对

的回应
http://abcde.com/api/OrgSchool/GetOrgSchools?%24inlinecount=allpages&%24top=10

$id: "2"
Address1: "hjhjk"
Address2: "jhjk"
Addresses: []
City: {$id:3, CityID_PK:1, StateID_FK:1, Code:KH, Name:ABC, Description:null,
                   EffectiveDate:null,…}
CityID_FK: 1
Country: {$ref:5}
CountryID_FK: 3
CreatedByUserID_FK: 1
DateCreated: "0001-01-01T00:00:00"
DateUpdated: "0001-01-01T00:00:00"
Description: "hkjlhkj"
EffectiveDate: "2013-12-25T00:00:00"
MailAttentionOfName: "hjkh"
Org: {$id:6, OrgID_PK:15, OrgCode:PBS updated, OrgName: Education Board,     OrgDescription:,…}
OrgID_FK: 15
OrgSchoolsID_PK: 3
PinZipCode: "3dgg"
RowStatu: null
RowStatusID_FK: 1
SchoolCode: "PBS-KHN"
SchoolName: "KHN"
State: {$ref:4}
StateID_FK: 1
TerminationDate: "2013-12-30T00:00:00"
UpdatedByUserID_FK: 1
User: null
User1: null

0 个答案:

没有答案