Skip to content

Commit

Permalink
Fix for where count where
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre321 committed Aug 11, 2014
1 parent b02c0c1 commit 2518821
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 19 additions & 1 deletion LinqToAnything.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,25 @@ public void CanHandleAnOperatorWhereClauseAgainstAVariable()
var items = pq.Where(s => s.Name == variable);
Assert.AreEqual("Item 07", items.ToArray().Single().Name);
}
[Test]
public void CanHandleASecondWhereClauseAfterACount()
{
DataQuery<SomeEntity> getPageFromDataSource = (info) => SomeDataSource(info);
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(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]
public void CanHandleAnOperatorWhereClauseOnAValueType()
{
DataQuery<SomeEntity> getPageFromDataSource = (info) => SomeDataSource(info);
IQueryable<SomeEntity> pq = new DelegateQueryable<SomeEntity>(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);
}

Expand Down Expand Up @@ -312,6 +323,13 @@ static IEnumerable<SomeEntity> 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")
Expand Down
3 changes: 2 additions & 1 deletion LinqToAnything/QueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public IQueryable<TElement> CreateQuery<TElement>(Expression expression)

public IEnumerable<TResult> GetEnumerable<TResult>()
{
var queryVisitor = _queryVisitor ?? (_queryVisitor = new QueryVisitor());
var queryVisitor = new QueryVisitor(_queryVisitor.QueryInfo.Clone());
var results = _dataQuery(queryVisitor.QueryInfo);
//if (queryVisitor.Select != null)
//{
Expand All @@ -58,6 +58,7 @@ public TResult Execute<TResult>(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();

Expand Down

0 comments on commit 2518821

Please sign in to comment.