有如下类~~~public class Intentionpublic long GoodsIdget;set;public int ActivityType get;set;public class OrderItem public long GoodsIdget;set;public int ActivityTypeget;set;~~~现在有变量orderItems类型为ListOrderI
可以使用Join操作符将Intention和OrderItem两个实体类进行连接查询,然后在Where子句中添加筛选条件即可,代码如下:
var result = dbContext.Intention.Join(
orderItems,
intention => new { intention.GoodsId, intention.ActivityType },
orderItem => new { orderItem.GoodsId, orderItem.ActivityType },
(intention, orderItem) => intention
).ToList();
上述代码中,Join操作符将Intention和OrderItem两个实体类连接起来,连接条件为Intention.GoodsId == OrderItem.GoodsId且Intention.ActivityType==OrderItem.ActivityType。在连接后的结果集中,我们只需要返回Intention实体类即可,因此在Select子句中只返回了intention。最后调用ToList方法将查询结果转换为List
原文地址: https://www.cveoy.top/t/topic/fdve 著作权归作者所有。请勿转载和采集!