codeice / linqtoexcel

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

Skip(someNumber) Doesn't Work on Linq to Excel Results #57

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Create a basic Excel file
2.Get the rows from it using the WorksheetRangeNoHeader() method and store them 
as a var
3.Try to use Skip(someNumber) on the query results

What is the expected output? What do you see instead?

It should Skip the specified number of results.

What version of the product are you using? On what operating system?

Windows 7, 1.5.5.0

Please provide any additional information below.

Original issue reported on code.google.com by LindsayM...@gmail.com on 12 Dec 2011 at 5:37

GoogleCodeExporter commented 8 years ago
Can you share the lines of code you are using.

That will help me debug the issue.

Original comment by paulyo...@gmail.com on 12 Dec 2011 at 2:24

GoogleCodeExporter commented 8 years ago
I also found this issue at 1.5.4 version. 

Code example:
var excel = new ExcelQueryFactory();
excel.FileName = "Test.xlsx";//file has more then two rows
excel.AddMapping<ExcelDataModel>(x => x.Id, "Id");
var records = excel.Worksheet<ExcelDataModel>(sheetName);
Console.WriteLine("Total count " + records.Count());
var recordsWithSkip = excel.Worksheet<ExcelDataModel>(sheetName).Skip(1);
//next row throw error. foreach doesn't work too
Console.WriteLine("Skip count " + recordsWithSkip.Count());
//Workaround: use ToList()
//Console.WriteLine("Skip count " + recordsWithSkip.ToList().Count);

Original comment by kolpakov...@gmail.com on 30 Dec 2011 at 8:03

GoogleCodeExporter commented 8 years ago
You will need to call ToList() before you call Skip().

var records = excel.Worksheet<ExcelDataModel>(sheetName).ToList();
Console.WriteLine("Total count " + records.Count);
var recordsWithSkip = 
excel.Worksheet<ExcelDataModel>(sheetName).ToList().Skip(1);
//next row throw error. foreach doesn't work too
Console.WriteLine("Skip count " + recordsWithSkip.Count);

Original comment by paulyo...@gmail.com on 30 Dec 2011 at 2:39

GoogleCodeExporter commented 8 years ago
I see. I suggest it isn't normal for the linq. Am I wrong?

Original comment by kolpakov...@gmail.com on 31 Dec 2011 at 7:56

GoogleCodeExporter commented 8 years ago
Yea, using Skip() in linq is normal. 

Creating a custom linq provider that implements all the linq methods natively 
is extremely difficult and time consuming, so I've had to strike a balance 
between how many linq methods that are natively implemented verses how much 
time I have to implement each one.

Skip is one of those linq methods that I haven't implemented in LinqToExcel.

Fortunately there is an easy workaround that allows you to get the same 
functionality. You just have to call ToList() before calling Skip()

LinqToExcel is open source, and the nice thing about open source projects is 
that you can contribute code to them to provide the functionality you want, and 
you are more than welcomed to submit a pull request that implements the Skip 
functionality :-)

Original comment by paulyo...@gmail.com on 31 Dec 2011 at 12:41