Created
October 29, 2016 18:27
-
-
Save bangonkali/528f1b0a60b01f5f8a9b45bb1db378bc to your computer and use it in GitHub Desktop.
Classic Eager loading for entity framework.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GET api/values | |
[HttpGet, Route("branches")] | |
public IActionResult Branches() | |
{ | |
//_context.Regions.Where(u=>u.Business.BusinessId == ) | |
var regions = _context.Regions | |
.Include(x => x.Branches) | |
.Include(x => x.Business) | |
.ToList(); | |
foreach (var business in _context.Businesses) | |
{ | |
foreach (var region in regions.Where(u => u.BusinessFkId == business.BusinessId)) | |
{ | |
Debug.WriteLine(region.Name); | |
} | |
//foreach (var iRegion in business.Regions) | |
//{ | |
// Debug.WriteLine(iRegion.Name); | |
//} | |
} | |
return new ObjectResult(regions); | |
//return new ObjectResult(JsonConvert.SerializeObject(_context.Branches)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment