我正在使用EntityFramework(第一次)并且已经设法获得查询,更新等等。我有一个连接三个表的linq查询,如下所示:
//get a list of completed orders between the last run date of this job and NOW
var completedOrders = from orders in db.orders
join orderStatus in db.orderStatus
on orders.statusID equals orderStatus.statusID
join aspnetUsers in db.aspnet_Users
on orders.userID equals aspnetUsers.UserId
into joined
where (orderStatus.statusID == 2 || orderStatus.statusID == 3 || orderStatus.statusID == 5) && (orders.dateTimeStamp > job.lastRunDate && orders.dateTimeStamp < DateTime.Now || !job.lastRunDate.HasValue)
select joined;
然后我有一个简单的foreach循环:
foreach (var order in completedOrders)
{
//process here
}
我的问题是,如何获取foreach循环中的信息?我需要获取列数据,例如:
顺序[ “日期”]
虽然理想情况下我喜欢强烈输入,因为我正在使用实体框架。
非常感谢任何反馈。
提前致谢 人
答案 0 :(得分:1)
您应该删除into
并添加匿名类型:
...
on orders.userID equals aspnetUsers.UserId
where (orderStatus.statusID == 2 || orderStatus.statusID == 3 || orderStatus.statusID == 5) && (orders.dateTimeStamp > job.lastRunDate && orders.dateTimeStamp < DateTime.Now || !job.lastRunDate.HasValue)
select new { orders, orderStatus, aspnetUsers }
然后你可以遍历结果
foreach (var x in completedOrders)
{
// use x.orders.Date, etc.
}