How to write a linq query for the following SQL statement
select * from XYZTable
where ColumnA
in
( select ColumnA from XYZTable
GROUP BY ColumnA
Having Count(*)>1
)
order by ColumnA
How to write a linq query for the following SQL statement
select * from XYZTable
where ColumnA
in
( select ColumnA from XYZTable
GROUP BY ColumnA
Having Count(*)>1
)
order by ColumnA
Welcome sunuJoinsIn,
Use code tag to post your source code. Read How to use code tags?
[CODe=C#] ..... statements...
[/code]
LINQ statement:
var lst = from ep in dc.XYZTable group ep by ep.ColumnA into newgrp where newgrp.Count() > 1 orderby newgrp.Key from allrec in dc.XYZTable where allrec.ColumnA == newgrp.Key select allrec;
foreach (var rec in lst)
{
..
}
How to write a linq query for the following SQL statement
select * from XYZTable
where ColumnA
in
( select ColumnA from XYZTable
GROUP BY ColumnA
Having Count(*)>1
)
order by ColumnA
i looked to the best microsoft support msdn :)
http://msdn.microsoft.com/en-us/library/bb397676.aspx
here you can find the basics, also as far as i understood;
you got to have a "Column A" array stored in memory (if you are storing in file, you can easily write them to a memory by reading file, or if you are storing in database, you can easily write them to a memory by executing simple sql command), then...
List<FileType (for ex. int, float, char...)> YourListName = new List <FileType> () {ListValues};
IEnumarable <FileType> YourQueryName =
from Element in YourListName
where Element in ( from Element2 in YourListName
group Element2 by YourListName.Count() > 1 into NewGroupName
select NewGroupName; );
foreach ( FileType XGroup in YourQueryName)
{
foreach( FileType X in XGroup)
{
// Do something here for each x
}
}
i am also recently learned from msdn and waiting for your answer to reply if it works or not...
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.