tags:

views:

33

answers:

1

Hello,

I have a datasource with columns id,myname,eventime,ceasetime. I need to find out duplicate date ranges for a given Key. I tried to use -

(from data1 in myDatasource                                   
from data2 in myDatasource
where data1.SeqId != data2.SeqId 
&& data1.myname ==data2.myname
where data1.Event_Time <=data2.Cease_Time 
&& data1.Cease_Time > data2.Event_Time
select data1).Distinct();

but this is too slow, as i think, each row is compared with all the rest of rows. What I want to do is to first group by myName and then apply the where condition. The thing is the where condition can return multiple rows, Can anybody suggest someway

regards

+2  A: 
var lookup = from data1 in myDataSource
group by myDataSource.myName into g
where g.Count() > 1
select g;

This should do it. It'll return a Lookup of your objects grouped by their name, where there is more than one element for each name. If you want to flatten this back out, take lookup and call SelectMany on it:

var flatEnumerable = lookup.SelectMany(g=>g); //ToList(), ToArray(), etc will get you a concrete collection
KeithS
Hello, How can I apply the condition for the overlapping date range with group, this is for finding duplicates where myname is more than 1. I need to get all the rows where the condition is true from each group