c# linq to sql iterating through left join results

2019-09-08 04:58发布

I have a query that looks like this:

var emp = (from activeWO in context.ActiveWOs
                               join activeWOUpdated in context.ActiveWOUpdatedTimes on activeWO.PW_ID equals activeWOUpdated.PW_ID into dj
                               from activeWOUpdated in dj.DefaultIfEmpty()
                               where activeWO.WODC.Contains("IDC") 
                    select new { activeWO.WO_Status,activeWO.PW_ID, activeWO.T_Number, activeWOUpdated.CALCActiveTimeSec });

I have both tables mapped out in the .dbml file but as you can see above I am not pulling a table class object just but just 3 columns from 2 tables.

How can iterate through the results of emp?

2条回答
2楼-- · 2019-09-08 05:12

How can iterate through the results of emp?

Simplest would be:

foreach(var item in emp)
{
  Console.WriteLine(item.WO_Status);
  //other properties
}
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-09-08 05:23

You can iterate over the collection using foreach.

foreach (var item in emp)
{
    DoSomething(item.WO_Status);
}
查看更多
登录 后发表回答