I have 2 classes, SalesSubCategory and SalesCategory:
[Table("SALES.SubCategory")]
public class SalesSubCategory
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public int CategoryID { get; set; }
public string Name { get; set; }
[ForeignKey("CategoryID")]
public SalesCategory SalesCategory { get; set; }
}
[Table("SALES.Category")]
public class SalesCategory
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string Name { get; set; }
}
This Method returns SalesSubCategories List WITHOUT the SalesCategory Object loaded
public class TestController : Controller
{
private readonly MD_Context _context;
public TestController(MD_Context context)
{
_context = context;
}
public async Task<List<SalesSubCategory>> NoRelated()
{
var subCategories = await _context.SalesSubCategories.ToListAsync();
return subCategories;
}
This Method returns SalesSubCategories List WITH the SalesCategory Object loaded
public async Task<List<SalesSubCategory>> Related()
{
var subCategories = await _context.SalesSubCategories.ToListAsync();
var categories = await _context.SalesCategories.ToListAsync();
return subCategories;
}
MD_Context is configured to have lazy loading disabled:
Configuration.LazyLoadingEnabled = false;
Is this expected behavior? My preferred result is to NOT have the SalesCategory object entities pre-loaded.
Thank you.