C#linq到SQL迭代通过左联接结果[英] c# linq to sql iterating through left join results

本文是小编为大家收集整理的关于C#linq到SQL迭代通过左联接结果的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个看起来像这样的查询:

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 });

我的两个表都映射在.dbml文件中,但是如上所示,我不只是从2个表中拉出3列.

如何迭代emp的结果?

推荐答案

如何迭代EMP的结果?

最简单的是:

foreach(var item in emp)
{
  Console.WriteLine(item.WO_Status);
  //other properties
}

其他推荐答案

您可以使用foreach

在集合上迭代集合.

foreach (var item in emp)
{
    DoSomething(item.WO_Status);
}

本文地址:https://www.itbaoku.cn/post/1557172.html

问题描述

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?

推荐答案

How can iterate through the results of emp?

Simplest would be:

foreach(var item in emp)
{
  Console.WriteLine(item.WO_Status);
  //other properties
}

其他推荐答案

You can iterate over the collection using foreach.

foreach (var item in emp)
{
    DoSomething(item.WO_Status);
}