mkhuwaja / linqtoexcel

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

Unable to perform case insensitive compare #46

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. use .Trim(), .ToLower() or similar string manipulation on either side of the 
where comparison clause. 
2. use String.Compare function to attempt a case-insensitive compare

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

Example:
var ApproversList = (from x in excel.Worksheet<FileShareApprover>()
                                 where x.Share.Contains(fileShare, StringComparer.CurrentCultureIgnoreCase)
                                 select x).ToList();

Results in:

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at LinqToExcel.Query.WhereClauseExpressionTreeVisitor.GetColumnName(MethodCallExpression mExp)
   at LinqToExcel.Query.WhereClauseExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression mExp)
   at Remotion.Data.Linq.Parsing.ExpressionTreeVisitor.VisitExpression(Expression expression)
   at LinqToExcel.Query.WhereClauseExpressionTreeVisitor.VisitBinaryExpression(BinaryExpression bExp)
   at Remotion.Data.Linq.Parsing.ExpressionTreeVisitor.VisitExpression(Expression expression)
   at LinqToExcel.Query.SqlGeneratorQueryModelVisitor.VisitWhereClause(WhereClause whereClause, QueryModel queryModel, Int32 index)
   at Remotion.Data.Linq.Clauses.WhereClause.Accept(IQueryModelVisitor visitor, QueryModel queryModel, Int32 index)
   at Remotion.Data.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
   at LinqToExcel.Query.SqlGeneratorQueryModelVisitor.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
   at LinqToExcel.Query.SqlGeneratorQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at LinqToExcel.Query.ExcelQueryExecutor.GetSqlStatement(QueryModel queryModel)
   at LinqToExcel.Query.ExcelQueryExecutor.ExecuteCollection[T](QueryModel queryModel)
   at Remotion.Data.Linq.Clauses.StreamedData.StreamedSequenceInfo.ExecuteCollectionQueryModel[T](QueryModel queryModel, IQueryExecutor executor)
   at Remotion.Data.Linq.Clauses.StreamedData.StreamedSequenceInfo.ExecuteQueryModel(QueryModel queryModel, IQueryExecutor executor)
   at Remotion.Data.Linq.QueryModel.Execute(IQueryExecutor executor)
   at Remotion.Data.Linq.QueryProviderBase.Execute[TResult](Expression expression)
   at Remotion.Data.Linq.QueryableBase`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
 at....

What version of the product are you using? On what operating system?
Windows 7 x32, latest version from NuGet as at 2011-06-09

Please provide any additional information below.
 If this is the incorrect way to compare in a case-insensitive manner, could you please advise the correct way

Original issue reported on code.google.com by brett.ch...@gmail.com on 9 Jun 2011 at 4:44

GoogleCodeExporter commented 8 years ago
LinqToExcel doesn't support the case insensitive search, but you can retrieve 
all the spreadsheet rows into a list and then perform a Linq query on that list.

Here's an example of what that would look like:
var ApproversList = (from x in excel.Worksheet<FileShareApprover>().ToList()
                                 where x.Share.Contains(fileShare, StringComparer.CurrentCultureIgnoreCase)
                                 select x).ToList();

Notice I just added the ToList() method after calling Worksheet<>()

Original comment by paulyo...@gmail.com on 10 Jun 2011 at 9:16