首页 > 其他分享 >Entity Framework Classic Include

Entity Framework Classic Include

时间:2022-08-17 14:26:27浏览次数:89  
标签:product Classic orderDetail Framework AlsoInclude NET Include

Entity Framework Classic  Include

The Include method lets you add related entities to the query result.

In EF Classic, the Include method no longer returns an IQueryable but instead an IncludeDbQuery that allows you to chain multiple related objects to the query result by using the AlsoInclude and ThenInclude methods.

ctx.Customers
	.Include(customer => customer.Orders)
		.ThenInclude(order => order.OrderDetails)
		.ThenInclude(orderDetail => orderDetail.Product)
			.AlsoInclude(product => product.Category)
			.AlsoInclude(product => product.Supplier)
	.ToList();

Try it: NET Core | NET Framework

Note

  • If you want to include items from the same level, use AlsoInclude
  • If you want to include items from the next level, use ThenInclude
Limitation

DbQuery

Chaining includes only work if the first include call is from a DbQuery. If you used some LINQ and the query is currently an IQueryable, you can use the method AsDbQuery to tell the compiler that's a DbQuery. This restriction is currently required to avoid some side impact with queries that are not directly using the DbQuery class.

ctx.OrderDetails
	.Where(orderDetail => orderDetail.Quantity > 1)
	.AsDbQuery()
	.Include(orderDetail => orderDetail.Product)
		.AlsoInclude(product => product.Category)
		.AlsoInclude(product => product.Supplier)
	.ToList();

Try it: NET Core | NET Framework

It's planned to remove this limitation.

 

标签:product,Classic,orderDetail,Framework,AlsoInclude,NET,Include
From: https://www.cnblogs.com/chucklu/p/16595022.html

相关文章

  • CF464E The Classic Problem
    题解:首先要注意到一个数+$2^k$的在二进制中的运算过程是将一段连续都为1的区间都赋0,然后将下一个为0的位置改为1想到可持久化数组然后dij一下就好了有几个值得留下的......
  • Android xml include merger layout
    转载自:http://blog.csdn.net/a740169405/article/details/50473909并参考了https://cloud.tencent.com/developer/article/1444006Android官方提供了三个用来优化布局......
  • Django-rest-framework开发api接口
    django-rest-framework开发api接口(1)创建django项目drfdemo1并且创建一个名为app的应用django-adminstartprojectdrfdemo1pythonmanage.pystartappapp(2)安......
  • django restframework 后端接口权限
    REST_FRAMEWORK={'EXCEPTION_HANDLER':'djangoProject.utils.exception.custom_exception_handler',#在不需要权限就能访问的视图设置permissions_classes......
  • CF464E The Classic Problem(线段树 最短路)
    CF464ETheClassicProblem\(\bigstar\texttt{Hint}\):发现没有什么好的突破口?为什么不想想怎样才能实现题目中\(2^x\)的加减法呢?可见每次加减法,我们要做的是将添加的......
  • VS2010 + Mysql5.7 使用ADO.Net Entity Framework
        系统很LOW,不想花太多时间来升级,可想做点什么,总是这也不行那也不行,更种安装要不就是vs版本太低,要不不支持低版本的mysql,调试起来很费时。用老版办法写代码又太费......
  • 使用网关Zuul的时候,报java.lang.NoSuchMethodError: org.springframework.boot.web.s
    最近遇到一个困扰了我很久的问题(关于Zuul):报错界面如下:  原因是因为:Zuul与SpringBoot版本冲突,而SpringCloud又和SpringBoot版本关联,SpringCloud与SpringBoot......