开发者

Grouping using LINQ [duplicate]

开发者 https://www.devze.com 2022-12-19 01:58 出处:网络
This question already has answers here: LINQ to XML in VB.NET (4 answers) Closed 2 years ago. I\'m having a heck of a time with transforming a simple SQL 开发者_JAVA百科Query into a LINQ
This question already has answers here: LINQ to XML in VB.NET (4 answers) Closed 2 years ago.

I'm having a heck of a time with transforming a simple SQL 开发者_JAVA百科Query into a LINQ query(using vb btw)

Here is my SQL:

SELECT     USRDEFND5
FROM         int_gp_employee
GROUP BY USRDEFND5

The xml looks like this:

<int_gp_employee>
  <row>
    ....
    <usrdefnd5>Some GUID</usrdefnd5>
  </row>
</int_gp_employee>

I've tried a number of different variations of the LINQ. My current statement is:

From b In xmlFile...<row> Group b...<usrdefnd5> By b...<usrdefnd5> INTO group

when I foreach through the resulting collection, EVERY line (17000) shows up.

Thanks for taking a look.


I'm afraid I don't know the VB equivalent for sure, but in C# this would be:

var query = from row in xmlFile.Descendants("row")
            group row by (string) row.Element("usrdefnd5");

Without using XML literals, the VB would be:

Dim query = From row In document.Descendants("row") _
            Group row By CStr(row.Element("usrdefnd5"))

EDIT: If you just need the distinct keys, then something like:

Dim query = From row In document.Descendants("row") _
            Select CStr(row.Element("usrdefnd5")) _
            Distinct
0

精彩评论

暂无评论...
验证码 换一张
取 消