0

I am using ASP.NET MVC5 WebAPI with Entity Framework 6.

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()
       );
}

The .Include is working only for Org & City, Country & State are returned as {$ref:5} & {$ref:4}

All the columns are foreign keys and there are related rows in the reference tables.

What can I do so that all the immediate relational data is also included in the response?

I tried using

db.Configuration.LazyLoadingEnabled = false, 

but of no effect.

JSON Response (Partial output only).

The output is in response to

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
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
NSS
  • 1,835
  • 2
  • 29
  • 66

0 Answers0