2010-02-05 62 views
6

我有一個時間赫克與轉化一個簡單的SQL查詢到LINQ查詢(用vb BTW)分組使用LINQ

這裏是我的SQL:

SELECT  USRDEFND5 
FROM   int_gp_employee 
GROUP BY USRDEFND5 

的XML是什麼樣子這個:

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

我已經嘗試了一些不同的LINQ的變化。我現在的說法是:

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

,當我在結果集合中的foreach,每一行(17000)出現。

感謝您的關注。

回答

0

發現在另一個線程答案:

Here

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

應該已經

From row IN xmlFile...<row> SELECT row.<USRDEFND5>.value distinct

那得到的獨特價值,只是該列。

3

我怕我不知道VB相當於肯定的,但在C#中,這將是:

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

不使用XML文本,VB的將是:

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

編輯:如果你只需要在不同的鍵,然後是這樣的:

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

仍返回所有這些。我正在尋找usrdefnd5的不同值。 – spuppett 2010-02-05 17:53:48

+0

它應該返回所有行,但按該字段分組。每個組都將是具有該鍵的一系列行。你是否需要行,或者*只是*鍵? – 2010-02-05 18:09:35

+0

我只需要鑰匙。 – spuppett 2010-02-05 18:16:11