c# - Linq to SQL query to find partial duplicates -
i have looked @ lots of questions regarding linq sql , duplicates couldn't find leads me in right direction situation.
i have view want query return rows have same columna different columnb.
myview
- id
- columna
- columnb
i can values of columna following t-sql query...
select a.columna, count(*) ( select b.columna, b.columnb myview b group b.columna, b.columnb ) group a.columna having count(*) > 1
..but translate linq sql , return id column well, if possible.
any appreciated.
nb. asp.net 4.0, c#, linq sql, sql server in use.
updated
sample data:
id, columna, columnb 1, aaa, a100 2, aaa, a100 3, aaa, b200 4, bbb, c300 5, bbb, c300
desired result:
id, columna, columnb 1, aaa, a100 2, aaa, a100 3, aaa, b200
(as column same, columnb different. id 4 , 5 not returned columnb values same.)
updated 2
somehow created following query part of wanted return columna value. improvements or suggestions on getting id appreciated.
list<string> duplicates = (from in (from b in dc.mytables group b new { b.columna, b.columnb } c select new { columna = c.key.columna, columnb = c.key.columnb }) group a.columna d d.count() > 1 select d.key).tolist();
doing sql tricky because asking have list of id's subgroup showing 1 column each value of a. not relational. accomplished using famous xml trick create concatenated string id values.
however in linq asking easy, because not limited flat row. can generate result first value string, , second list example. can generate result each unique columna field 1 , field 2 list of id's. can done using groupby into. take @ linq documentation or examples , should have no problem adapting data.
Comments
Post a Comment