codeice / linqtoexcel

Automatically exported from code.google.com/p/linqtoexcel
0 stars 0 forks source link

Distinct() not working #66

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.  var excel = new ExcelQueryFactory("test.xls");
2.  var distinctNames = (from row in excel.WorkSheet()
                     select row["ColB"]).Distinct();

What is the expected output? What do you see instead?
Expected results:
Adam
Jane
Eve

Instead, I get:
{"LinqToExcel only provides support for the Distinct() method when a single 
property is selected."}

What version of the product are you using? On what operating system?
Windows XP SP 3 using Visual Studio 2010 on .Net Framework 4

Please provide any additional information below.
I think I followed your instructions but I can't get the valid output.  What am 
I doing wrong?

Original issue reported on code.google.com by denny.ma...@gmail.com on 4 May 2012 at 7:13

Attachments:

GoogleCodeExporter commented 8 years ago
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 4 May 2012 at 9:35