我有2个类,SalesSubCategory和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; } }
此方法返回SalesSubCategories List而不加载SalesCategory对象
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; }
此方法返回SalesSubCategories列表,并加载SalesCategory对象
public async Task<List<SalesSubCategory>> Related() { var subCategories = await _context.SalesSubCategories.ToListAsync(); var categories = await _context.SalesCategories.ToListAsync(); return subCategories; }
MD_Context配置为禁用延迟加载:
Configuration.LazyLoadingEnabled = false;
这是预期的行为吗?我的首选结果是不预先加载SalesCategory对象实体.
谢谢.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。