I am fairly new to using Linq which is turning out a bit tricky for me on filtering the best datasource from a c# datatable. I need to perform the following filtering to a datatable. The background behind the data is that it is a set of records which contain independent redundancies from different datasources for the purpose of failsafe. In case one datasource had become corrupted at some point, a secondary or third datasource would become the primary source for that event thread.
Original Data (for example):
signintable:
source First Last
d1 John Smith
d1 John Smith
d3 John Smith
d1 Jane Doe
d2 Jane Doe
d3 Richard Miles
d3 Richard Miles
d1 Richard Miles
I would like to add two columns to this: a count of unique members of groups by(firstname, lastname and datasource), and a uniqueRecordGroupnumber based on distinct group (firstname, lastname, datasource) but ordered by whichever datasource for that particular first name last name has the most records, to the least.
source First Last Count UniqueRecordGroup
d1 John Smith 2 1
d1 John Smith 2 1
d3 John Smith 1 2
d1 Jane Doe 1 1
d2 Jane Doe 1 2
d3 Richard Miles 2 1
d3 Richard Miles 2 1
d1 Richard Miles 1 2
Then I would finally filter out only the primary (unique record group 1) in order to eliminate the redundancies/ less reliable datasource for that particular record.
source First Last Count UniqueRecordGroup
d1 John Smith 2 1
d1 John Smith 2 1
d1 Jane Doe 1 1
d3 Richard Miles 2 1
d3 Richard Miles 2 1
How are the above steps accomplished using Linq on a datatable (for example datatable signintable)?
Thank you.
After now completing this application feature, I would not recommend trying to use Linq for this purpose. I found that there were not many resources and forums expressly for more involved Linq queries, whereas with Oracle, or SQL, plenty of forums and posts at least on the parts that were needed. So rather than add the feature in the c#/asp.net layer in Linq script, I added it in the database query layer.
In Oracle, I accomplished the above by 4 steps: