【发布时间】:2017-02-14 19:12:55
【问题描述】:
在 Linq 方面需要一些帮助。
我有一个如下所示的数据表 I just have the W_text with me to search
使用上面的数据表,我想提取具有以下结果的行子集
The key to search is "First Employee"
如您所见,我想获取其中 W_Text 值为“First”和“Employee”但具有相同 l_id 的行的子集。
在数据库术语中,这将是一个 Select * from Table 1 where W_Text in ('First','Employee') group by l_id with l_id > 1(或类似的东西)。
如何在 C# 中使用数据表实现这一点?
我尝试使用以下代码,但这也为我提供了包含其他行的整个数据表。我不确定如何使用 group by 和 having 子句。如果有人可以在这方面帮助我,我会很高兴。
var results = from myRow in dtResult.AsEnumerable()
where myRow.Field<string>("W_Text") == "First" ||
myRow.Field<string>("W_Text") == "Employee"
select myRow;
dtCopy = results.CopyToDataTable();
【问题讨论】: