almost ready to support more complex filtering.

This commit is contained in:
David 2018-02-12 11:15:22 -06:00
parent bd213f8b3f
commit 507b64c34b

View File

@ -2,10 +2,13 @@
using PoweredSoft.DynamicLinq.Dal.Pocos; using PoweredSoft.DynamicLinq.Dal.Pocos;
using PoweredSoft.DynamicLinq.Extensions; using PoweredSoft.DynamicLinq.Extensions;
using PoweredSoft.DynamicLinq.Fluent; using PoweredSoft.DynamicLinq.Fluent;
using PoweredSoft.DynamicLinq.Helpers;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -95,5 +98,131 @@ namespace PoweredSoft.DynamicLinq.Test
Assert.IsTrue(first.Id == 3); Assert.IsTrue(first.Id == 3);
Assert.IsTrue(second.Id == 1); Assert.IsTrue(second.Id == 1);
} }
//[TestMethod]
//public void Test()
//{
// var authors = new List<Author>()
// {
// new Author
// {
// Id = 1,
// FirstName = "David",
// LastName = "Lebee",
// Posts = new List<Post>
// {
// new Post
// {
// Id = 1,
// AuthorId = 1,
// Title = "Match",
// Content = "ABC",
// Comments = new List<Comment>()
// {
// new Comment()
// {
// Id = 1,
// DisplayName = "John Doe",
// CommentText = "!@#$!@#!@#",
// Email = "John.doe@me.com"
// }
// }
// },
// new Post
// {
// Id = 2,
// AuthorId = 1,
// Title = "Match",
// Content = "ABC"
// }
// }
// },
// new Author
// {
// Id = 2,
// FirstName = "Chuck",
// LastName = "Norris",
// Posts = new List<Post>
// {
// new Post
// {
// Id = 3,
// AuthorId = 2,
// Title = "Match",
// Content = "ASD",
// },
// new Post
// {
// Id = 4,
// AuthorId = 2,
// Title = "DontMatch",
// Content = "ASD",
// }
// }
// }
// };
// // the query.
// var query = authors.AsQueryable();
// //// first recursion.
// //var typeOfClass = typeof(Author);
// //var parameter = Expression.Parameter(typeOfClass, "t");
// //var posts = Expression.PropertyOrField(parameter, "Posts");
// //// second recursion
// //{
// // var subListType = posts.Type.GetGenericArguments().First();
// // var innerParam = Expression.Parameter(subListType, "t2");
// // var field = Expression.PropertyOrField(innerParam, "Title");
// // var innerCondition = PoweredSoft.DynamicLinq.Helpers.QueryableHelpers.GetConditionExpressionForMember(innerParam, field, ConditionOperators.Equal, Expression.Constant("Match"));
// // var lambda = Expression.Lambda(innerCondition, innerParam);
// // // any
// // var anyMethod = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).First(t => t.Name == "All" && t.GetParameters().Count() == 2);
// // var genericAnyMethod = anyMethod.MakeGenericMethod(subListType);
// // var subExpression = Expression.Call(genericAnyMethod, posts, lambda);
// // var finalLambda = Expression.Lambda<Func<Author, bool>>(subExpression, parameter);
// // query = query.Where(finalLambda);
// //}
// var anyMethod = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public).First(t => t.Name == "Any" && t.GetParameters().Count() == 2);
// // first recursion.
// var typeOfClass = typeof(Author);
// var parameter = Expression.Parameter(typeOfClass, "t");
// var posts = Expression.PropertyOrField(parameter, "Posts");
// // second recursion
// {
// var subListType = posts.Type.GetGenericArguments().First();
// var innerParam = Expression.Parameter(subListType, "t2");
// var field = Expression.PropertyOrField(innerParam, "Comments");
// // any
// var genericAnyMethod = anyMethod.MakeGenericMethod(subListType);
// // third recursion
// {
// var innerParam2 = Expression.Parameter(typeof(Comment), "t3");
// var field2 = Expression.PropertyOrField(innerParam2, "Id");
// var innerCondition2 = QueryableHelpers.GetConditionExpressionForMember(innerParam2, field2, ConditionOperators.Equal, Expression.Constant(1L));
// var lambda = Expression.Lambda(innerCondition2, innerParam2);
// var generateAnyMethod2 = anyMethod.MakeGenericMethod(typeof(Comment));
// var subExpression2 = Expression.Call(generateAnyMethod2, field, lambda);
// var previousLambda = Expression.Lambda<Func<Post, bool>>(subExpression2, innerParam);
// var subExpression = Expression.Call(genericAnyMethod, posts, previousLambda);
// var finalLambda = Expression.Lambda<Func<Author, bool>>(subExpression, parameter);
// query = query.Where(finalLambda);
// }
// }
//}
} }
} }