From 2518821abb78cf15ac5c63bee4c2d2cc8266e3b0 Mon Sep 17 00:00:00 2001 From: mcintyre321 Date: Mon, 11 Aug 2014 16:46:40 +0100 Subject: [PATCH] Fix for where count where --- LinqToAnything.Tests/Tests.cs | 20 +++++++++++++++++++- LinqToAnything/QueryProvider.cs | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/LinqToAnything.Tests/Tests.cs b/LinqToAnything.Tests/Tests.cs index 87cd51d..be08dac 100644 --- a/LinqToAnything.Tests/Tests.cs +++ b/LinqToAnything.Tests/Tests.cs @@ -150,6 +150,17 @@ public void CanHandleAnOperatorWhereClauseAgainstAVariable() var items = pq.Where(s => s.Name == variable); Assert.AreEqual("Item 07", items.ToArray().Single().Name); } + [Test] + public void CanHandleASecondWhereClauseAfterACount() + { + DataQuery getPageFromDataSource = (info) => SomeDataSource(info); + IQueryable pq = new DelegateQueryable(getPageFromDataSource); + var items = pq.Where(s => s.Name == "Item 07"); + var count = items.Count(); + var items2 = items.Where(s => s.Name != "Item 07"); + Assert.AreEqual(0, items2.ToArray().Length); + + } [Test] @@ -157,7 +168,7 @@ public void CanHandleAnOperatorWhereClauseOnAValueType() { DataQuery getPageFromDataSource = (info) => SomeDataSource(info); IQueryable pq = new DelegateQueryable(getPageFromDataSource); - var items = pq.Where(s => s.Index != null && s.Index == 7); + var items = pq.Where(s => s.Index != 0 && s.Index == 7); Assert.AreEqual("Item 07", items.ToArray().Single().Name); } @@ -312,6 +323,13 @@ static IEnumerable SomeDataSource(QueryInfo qi) { query = query.Where(where.PropertyName + " == @0", where.Value); } + + if (clause.Operator == "NotEqual") + { + query = query.Where(where.PropertyName + " != @0", where.Value); + } + + } if (clause.Operator == "OrElse") diff --git a/LinqToAnything/QueryProvider.cs b/LinqToAnything/QueryProvider.cs index f8458bb..40594e2 100644 --- a/LinqToAnything/QueryProvider.cs +++ b/LinqToAnything/QueryProvider.cs @@ -39,7 +39,7 @@ public IQueryable CreateQuery(Expression expression) public IEnumerable GetEnumerable() { - var queryVisitor = _queryVisitor ?? (_queryVisitor = new QueryVisitor()); + var queryVisitor = new QueryVisitor(_queryVisitor.QueryInfo.Clone()); var results = _dataQuery(queryVisitor.QueryInfo); //if (queryVisitor.Select != null) //{ @@ -58,6 +58,7 @@ public TResult Execute(Expression expression) { var methodCallExpression = (MethodCallExpression)expression; var queryVisitor = new QueryVisitor(_queryVisitor.QueryInfo.Clone()); + queryVisitor.Visit(expression); var array = _dataQuery(queryVisitor.QueryInfo).ToList(); var data = array.AsQueryable();