Closed GoogleCodeExporter closed 9 years ago
Yea, LinqToExcel does not currently support the Distinct method, and
unfortunately I do not have the extra bandwidth in my personal schedule to work
on this feature. If you're interested in digging into the source code and
submitting a patch, you can look at the VisitResultOperator() method in
SqlGeneratorQueryModelVisitor.cs
(https://github.com/paulyoder/LinqToExcel/blob/master/src/LinqToExcel/Query/SqlG
eneratorQueryModelVisitor.cs)
Original comment by paulyo...@gmail.com
on 10 Jun 2011 at 9:13
same problem.
how to use Distinct<>
Original comment by rahul.si...@zeuslearning.com
on 16 Nov 2011 at 10:18
@rahul
get all the data in arraylist and apply distinct on it
there is on way
if you are using dot net use LINQ
Original comment by deshmukh...@gmail.com
on 17 Nov 2011 at 7:30
There is a fix to support DISTINCT here:
https://github.com/assafshemesh/LinqToExcel
Still wasn't merged to main stream
Original comment by shemesh....@gmail.com
on 17 Nov 2011 at 8:04
I'm still working on merging assafshemesh code changes to use distinct. You can
either use his changes or you can use the workaround that deshmukhshivkumar
suggested by converting the results to a list and using distinct on the list.
Here is an example of using distinct on a list
(from row in excel.WorkSheet<Company>() select row.Name).ToList().Distinct();
Original comment by paulyo...@gmail.com
on 17 Nov 2011 at 12:32
With version 1.5.5, LinqToExcel now supports the Distinct() method natively!
Let me know if anyone has issues with using it.
Original comment by paulyo...@gmail.com
on 21 Nov 2011 at 4:11
I wonder if something has changed in the latest version. I tried to do
Distinct() and it doesn't seem to work. I even tried
"myQuery.ToList().Distinct();" and that didn't do a thing.
My example has over a 1000 rows with different countries. I want to get a
unique country list. I'm attaching the file for your review. Here's my code
for your review:
var masterDataXL = new ExcelQueryFactory(@"c:\temp\" + "DATA_TST.XLS");
var testList = (from x in masterDataXL.Worksheet("data_all")
select x["Source"]).Distinct();
What am I doing wrong here?
Thanks for any help, in advance.
Original comment by denny.ma...@gmail.com
on 1 May 2012 at 6:13
Attachments:
To use Distinct in LinqToExcel, you have to use a class that corresponds to the
row data.
public class WorksheetRow
{
public string ColA { get; set; }
public string ColB { get; set; }
}
var excel = new ExcelQueryFactory("worksheetFileName");
var distinctNames = (from row in excel.<WorksheetRow>WorkSheet()
select row.ColB).Distinct()
Original comment by paulyo...@gmail.com
on 5 May 2012 at 11:42
Original issue reported on code.google.com by
deshmukh...@gmail.com
on 7 Jun 2011 at 9:59