0

我正在使用 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 循环中的信息?我需要获取列数据,例如:

订购日期”]

虽然理想情况下我希望它是强类型的,因为我使用实体框架。

任何反馈将不胜感激。

提前感谢艾尔

4

1 回答 1

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.
 }
于 2012-09-13T18:08:08.380 回答