/// <summary> /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/> /// from a given type sequence that offer a public static <c>SupportedMethods</c> field. /// </summary> /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethods</c> /// field registered.</returns> public static MethodInfoBasedNodeTypeRegistry CreateFromTypes(IEnumerable <Type> searchedTypes) { ArgumentUtility.CheckNotNull("searchedTypes", searchedTypes); var expressionNodeTypes = from t in searchedTypes where typeof(IExpressionNode).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()) select t; var supportedMethodsForTypes = from t in expressionNodeTypes let supportedMethodsField = t.GetRuntimeField("SupportedMethods") select new { Type = t, Methods = supportedMethodsField != null && supportedMethodsField.IsStatic ? (IEnumerable <MethodInfo>)supportedMethodsField.GetValue(null) : Enumerable.Empty <MethodInfo>() }; var registry = new MethodInfoBasedNodeTypeRegistry(); foreach (var methodsForType in supportedMethodsForTypes) { registry.Register(methodsForType.Methods, methodsForType.Type); } return(registry); }
public NHibernateNodeTypeProvider() { var methodInfoRegistry = new MethodInfoBasedNodeTypeRegistry(); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("Fetch") }, typeof(FetchOneExpressionNode)); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("FetchMany") }, typeof(FetchManyExpressionNode)); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("ThenFetch") }, typeof(ThenFetchOneExpressionNode)); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("ThenFetchMany") }, typeof(ThenFetchManyExpressionNode)); methodInfoRegistry.Register( new[] { typeof(LinqExtensionMethods).GetMethod("Cacheable"), typeof(LinqExtensionMethods).GetMethod("CacheMode"), typeof(LinqExtensionMethods).GetMethod("CacheRegion"), }, typeof(CacheableExpressionNode)); methodInfoRegistry.Register( new[] { ReflectionHelper.GetMethodDefinition(() => Queryable.AsQueryable(null)), ReflectionHelper.GetMethodDefinition(() => Queryable.AsQueryable<object>(null)), }, typeof(AsQueryableExpressionNode) ); var nodeTypeProvider = ExpressionTreeParser.CreateDefaultNodeTypeProvider(); nodeTypeProvider.InnerProviders.Add(methodInfoRegistry); defaultNodeTypeProvider = nodeTypeProvider; }
/// <summary> /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/> /// from a given type sequence that offer a public static <c>SupportedMethods</c> field. /// </summary> /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethods</c> /// field registered.</returns> public static MethodInfoBasedNodeTypeRegistry CreateFromTypes (IEnumerable<Type> searchedTypes) { ArgumentUtility.CheckNotNull ("searchedTypes", searchedTypes); var expressionNodeTypes = from t in searchedTypes where typeof (IExpressionNode).GetTypeInfo().IsAssignableFrom (t.GetTypeInfo()) select t; var supportedMethodsForTypes = from t in expressionNodeTypes let supportedMethodsField = t.GetRuntimeField ("SupportedMethods") select new { Type = t, Methods = supportedMethodsField != null && supportedMethodsField.IsStatic ? (IEnumerable<MethodInfo>) supportedMethodsField.GetValue (null) : Enumerable.Empty<MethodInfo>() }; var registry = new MethodInfoBasedNodeTypeRegistry(); foreach (var methodsForType in supportedMethodsForTypes) { registry.Register (methodsForType.Methods, methodsForType.Type); } return registry; }
public static IQueryParser CreateQueryParser() { //Create Custom node registry var customNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry(); //register the "Nest" clause type customNodeTypeRegistry.Register(NestExpressionNode.SupportedMethods, typeof(NestExpressionNode)); //register the "Explain" expression node parser customNodeTypeRegistry.Register(ExplainExpressionNode.SupportedMethods, typeof(ExplainExpressionNode)); //register the "UseKeys" expression node parser customNodeTypeRegistry.Register(UseKeysExpressionNode.SupportedMethods, typeof(UseKeysExpressionNode)); //This creates all the default node types var nodeTypeProvider = ExpressionTreeParser.CreateDefaultNodeTypeProvider(); //add custom node provider to the providers nodeTypeProvider.InnerProviders.Add(customNodeTypeRegistry); var transformerRegistry = ExpressionTransformerRegistry.CreateDefault(); var processor = ExpressionTreeParser.CreateDefaultProcessor(transformerRegistry); var expressionTreeParser = new ExpressionTreeParser(nodeTypeProvider, processor); var queryParser = new QueryParser(expressionTreeParser); return queryParser; }
public void SetUp () { _methodInfoBasedNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry (); _methodInfoBasedNodeTypeRegistry.Register (WhereExpressionNode.GetSupportedMethods(), typeof (WhereExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (SelectExpressionNode.GetSupportedMethods(), typeof (SelectExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (TakeExpressionNode.GetSupportedMethods(), typeof (TakeExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (CountExpressionNode.GetSupportedMethods(), typeof (CountExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (JoinExpressionNode.GetSupportedMethods(), typeof (JoinExpressionNode)); _parser = new MethodCallExpressionParser (_methodInfoBasedNodeTypeRegistry); _source = ExpressionNodeObjectMother.CreateMainSource(); }
public void SetUp () { _methodInfoBasedNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry(); _methodInfoBasedNodeTypeRegistry.Register (WhereExpressionNode.SupportedMethods, typeof (WhereExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (SelectExpressionNode.SupportedMethods, typeof (SelectExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (TakeExpressionNode.SupportedMethods, typeof (TakeExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (CountExpressionNode.SupportedMethods, typeof (CountExpressionNode)); _methodInfoBasedNodeTypeRegistry.Register (ContainsExpressionNode.SupportedMethods, typeof (ContainsExpressionNode)); _expressionTreeParser = new ExpressionTreeParser (_methodInfoBasedNodeTypeRegistry, new PartialEvaluatingExpressionTreeProcessor() ); _intSource = new[] { 1, 2, 3 }.AsQueryable (); }
public static void Enable() { var queryParser = typeof(NhRelinqQueryParser).GetField("QueryParser", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as QueryParser; if (queryParser == null) { throw new NullReferenceException("The QueryParser field was not found"); } var nhNodeTypeProvider = queryParser.NodeTypeProvider as NHibernateNodeTypeProvider; var nodeTypeProvider = nhNodeTypeProvider.GetType().GetField("defaultNodeTypeProvider", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(nhNodeTypeProvider) as CompoundNodeTypeProvider; var methodInfoRegistry = new MethodInfoBasedNodeTypeRegistry(); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("InnerFetch") }, typeof(InnerFetchOneExpressionNode)); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("InnerFetchMany") }, typeof(InnerFetchManyExpressionNode)); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("ThenInnerFetch") }, typeof(ThenInnerFetchOneExpressionNode)); methodInfoRegistry.Register(new[] { typeof(EagerFetchingExtensionMethods).GetMethod("ThenInnerFetchMany") }, typeof(ThenInnerFetchManyExpressionNode)); nodeTypeProvider.InnerProviders.Add(methodInfoRegistry); var resultOperatorMap = typeof(QueryModelVisitor).GetField("ResultOperatorMap", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as ResultOperatorMap; if (resultOperatorMap == null) { throw new NullReferenceException("The ResultOperatorMap field was not found"); } var innerMap = typeof(ResultOperatorMap).GetField("_map", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(resultOperatorMap) as Dictionary<System.Type, ResultOperatorProcessorBase>; if (innerMap == null) { throw new NullReferenceException("The _map field was not found"); } innerMap.Remove(typeof(FetchOneRequest)); innerMap.Remove(typeof(FetchManyRequest)); resultOperatorMap.Add<FetchOneRequest, ProcessLeftFetchOne>(); resultOperatorMap.Add<FetchManyRequest, ProcessLeftFetchMany>(); resultOperatorMap.Add<InnerFetchOneRequest, ProcessInnerFetchOne>(); resultOperatorMap.Add<InnerFetchManyRequest, ProcessInnerFetchMany>(); }
/// <summary> /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and registers all relevant <see cref="IExpressionNode"/> implementations in the <b>Remotion.Linq</b> assembly. /// </summary> /// <returns> /// A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types in the <b>Remotion.Linq</b> assembly registered. /// </returns> public static MethodInfoBasedNodeTypeRegistry CreateFromRelinqAssembly() { var registry = new MethodInfoBasedNodeTypeRegistry(); registry.Register(AggregateExpressionNode.GetSupportedMethods(), typeof(AggregateExpressionNode)); registry.Register(AggregateFromSeedExpressionNode.GetSupportedMethods(), typeof(AggregateFromSeedExpressionNode)); registry.Register(AllExpressionNode.GetSupportedMethods(), typeof(AllExpressionNode)); registry.Register(AnyExpressionNode.GetSupportedMethods(), typeof(AnyExpressionNode)); registry.Register(AsQueryableExpressionNode.GetSupportedMethods(), typeof(AsQueryableExpressionNode)); registry.Register(AverageExpressionNode.GetSupportedMethods(), typeof(AverageExpressionNode)); registry.Register(CastExpressionNode.GetSupportedMethods(), typeof(CastExpressionNode)); registry.Register(ConcatExpressionNode.GetSupportedMethods(), typeof(ConcatExpressionNode)); registry.Register(ContainsExpressionNode.GetSupportedMethods(), typeof(ContainsExpressionNode)); registry.Register(CountExpressionNode.GetSupportedMethods(), typeof(CountExpressionNode)); registry.Register(DefaultIfEmptyExpressionNode.GetSupportedMethods(), typeof(DefaultIfEmptyExpressionNode)); registry.Register(DistinctExpressionNode.GetSupportedMethods(), typeof(DistinctExpressionNode)); registry.Register(ExceptExpressionNode.GetSupportedMethods(), typeof(ExceptExpressionNode)); registry.Register(FirstExpressionNode.GetSupportedMethods(), typeof(FirstExpressionNode)); registry.Register(GroupByExpressionNode.GetSupportedMethods(), typeof(GroupByExpressionNode)); registry.Register(GroupByWithResultSelectorExpressionNode.GetSupportedMethods(), typeof(GroupByWithResultSelectorExpressionNode)); registry.Register(GroupJoinExpressionNode.GetSupportedMethods(), typeof(GroupJoinExpressionNode)); registry.Register(IntersectExpressionNode.GetSupportedMethods(), typeof(IntersectExpressionNode)); registry.Register(JoinExpressionNode.GetSupportedMethods(), typeof(JoinExpressionNode)); registry.Register(LastExpressionNode.GetSupportedMethods(), typeof(LastExpressionNode)); registry.Register(LongCountExpressionNode.GetSupportedMethods(), typeof(LongCountExpressionNode)); registry.Register(MaxExpressionNode.GetSupportedMethods(), typeof(MaxExpressionNode)); registry.Register(MinExpressionNode.GetSupportedMethods(), typeof(MinExpressionNode)); registry.Register(OfTypeExpressionNode.GetSupportedMethods(), typeof(OfTypeExpressionNode)); registry.Register(OrderByDescendingExpressionNode.GetSupportedMethods(), typeof(OrderByDescendingExpressionNode)); registry.Register(OrderByExpressionNode.GetSupportedMethods(), typeof(OrderByExpressionNode)); registry.Register(ReverseExpressionNode.GetSupportedMethods(), typeof(ReverseExpressionNode)); registry.Register(SelectExpressionNode.GetSupportedMethods(), typeof(SelectExpressionNode)); registry.Register(SelectManyExpressionNode.GetSupportedMethods(), typeof(SelectManyExpressionNode)); registry.Register(SingleExpressionNode.GetSupportedMethods(), typeof(SingleExpressionNode)); registry.Register(SkipExpressionNode.GetSupportedMethods(), typeof(SkipExpressionNode)); registry.Register(SumExpressionNode.GetSupportedMethods(), typeof(SumExpressionNode)); registry.Register(TakeExpressionNode.GetSupportedMethods(), typeof(TakeExpressionNode)); registry.Register(ThenByDescendingExpressionNode.GetSupportedMethods(), typeof(ThenByDescendingExpressionNode)); registry.Register(ThenByExpressionNode.GetSupportedMethods(), typeof(ThenByExpressionNode)); registry.Register(UnionExpressionNode.GetSupportedMethods(), typeof(UnionExpressionNode)); registry.Register(WhereExpressionNode.GetSupportedMethods(), typeof(WhereExpressionNode)); return(registry); }
/// <summary> /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and registers all relevant <see cref="IExpressionNode"/> implementations in the <b>Remotion.Linq</b> assembly. /// </summary> /// <returns> /// A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types in the <b>Remotion.Linq</b> assembly registered. /// </returns> public static MethodInfoBasedNodeTypeRegistry CreateFromRelinqAssembly () { var registry = new MethodInfoBasedNodeTypeRegistry(); registry.Register (AggregateExpressionNode.GetSupportedMethods(), typeof (AggregateExpressionNode)); registry.Register (AggregateFromSeedExpressionNode.GetSupportedMethods(), typeof (AggregateFromSeedExpressionNode)); registry.Register (AllExpressionNode.GetSupportedMethods(), typeof (AllExpressionNode)); registry.Register (AnyExpressionNode.GetSupportedMethods(), typeof (AnyExpressionNode)); registry.Register (AverageExpressionNode.GetSupportedMethods(), typeof (AverageExpressionNode)); registry.Register (CastExpressionNode.GetSupportedMethods(), typeof (CastExpressionNode)); registry.Register (ConcatExpressionNode.GetSupportedMethods(), typeof (ConcatExpressionNode)); registry.Register (ContainsExpressionNode.GetSupportedMethods(), typeof (ContainsExpressionNode)); registry.Register (CountExpressionNode.GetSupportedMethods(), typeof (CountExpressionNode)); registry.Register (DefaultIfEmptyExpressionNode.GetSupportedMethods(), typeof (DefaultIfEmptyExpressionNode)); registry.Register (DistinctExpressionNode.GetSupportedMethods(), typeof (DistinctExpressionNode)); registry.Register (ExceptExpressionNode.GetSupportedMethods(), typeof (ExceptExpressionNode)); registry.Register (FirstExpressionNode.GetSupportedMethods(), typeof (FirstExpressionNode)); registry.Register (GroupByExpressionNode.GetSupportedMethods(), typeof (GroupByExpressionNode)); registry.Register (GroupByWithResultSelectorExpressionNode.GetSupportedMethods(), typeof (GroupByWithResultSelectorExpressionNode)); registry.Register (GroupJoinExpressionNode.GetSupportedMethods(), typeof (GroupJoinExpressionNode)); registry.Register (IntersectExpressionNode.GetSupportedMethods(), typeof (IntersectExpressionNode)); registry.Register (JoinExpressionNode.GetSupportedMethods(), typeof (JoinExpressionNode)); registry.Register (LastExpressionNode.GetSupportedMethods(), typeof (LastExpressionNode)); registry.Register (LongCountExpressionNode.GetSupportedMethods(), typeof (LongCountExpressionNode)); registry.Register (MaxExpressionNode.GetSupportedMethods(), typeof (MaxExpressionNode)); registry.Register (MinExpressionNode.GetSupportedMethods(), typeof (MinExpressionNode)); registry.Register (OfTypeExpressionNode.GetSupportedMethods(), typeof (OfTypeExpressionNode)); registry.Register (OrderByDescendingExpressionNode.GetSupportedMethods(), typeof (OrderByDescendingExpressionNode)); registry.Register (OrderByExpressionNode.GetSupportedMethods(), typeof (OrderByExpressionNode)); registry.Register (ReverseExpressionNode.GetSupportedMethods(), typeof (ReverseExpressionNode)); registry.Register (SelectExpressionNode.GetSupportedMethods(), typeof (SelectExpressionNode)); registry.Register (SelectManyExpressionNode.GetSupportedMethods(), typeof (SelectManyExpressionNode)); registry.Register (SingleExpressionNode.GetSupportedMethods(), typeof (SingleExpressionNode)); registry.Register (SkipExpressionNode.GetSupportedMethods(), typeof (SkipExpressionNode)); registry.Register (SumExpressionNode.GetSupportedMethods(), typeof (SumExpressionNode)); registry.Register (TakeExpressionNode.GetSupportedMethods(), typeof (TakeExpressionNode)); registry.Register (ThenByDescendingExpressionNode.GetSupportedMethods(), typeof (ThenByDescendingExpressionNode)); registry.Register (ThenByExpressionNode.GetSupportedMethods(), typeof (ThenByExpressionNode)); registry.Register (UnionExpressionNode.GetSupportedMethods(), typeof (UnionExpressionNode)); registry.Register (WhereExpressionNode.GetSupportedMethods(), typeof (WhereExpressionNode)); return registry; }
/// <summary> /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/> /// from a given type sequence that offer a public static <c>SupportedMethods</c> field. /// </summary> /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethods</c> /// field registered.</returns> public static MethodInfoBasedNodeTypeRegistry CreateFromTypes(IEnumerable <Type> searchedTypes) { ArgumentUtility.CheckNotNull("searchedTypes", searchedTypes); var expressionNodeTypes = from t in searchedTypes where typeof(IExpressionNode).IsAssignableFrom(t) select t; var supportedMethodsForTypes = from t in expressionNodeTypes let supportedMethodsField = t.GetField("SupportedMethods", BindingFlags.Static | BindingFlags.Public) select new { Type = t, Methods = supportedMethodsField != null ? (IEnumerable <MethodInfo>)supportedMethodsField.GetValue(null) : Enumerable.Empty <MethodInfo>() }; var registry = new MethodInfoBasedNodeTypeRegistry(); foreach (var methodsForType in supportedMethodsForTypes) { List <MethodInfo> methods = new List <MethodInfo>(); foreach (var methodInfo in methodsForType.Methods) { if (methodInfo.DeclaringType.IsGenericType && !methodInfo.DeclaringType.IsGenericTypeDefinition) { var genericMethod = methodInfo.DeclaringType.GetGenericTypeDefinition().GetMethod(methodInfo.Name); methods.Add(genericMethod); } else { methods.Add(methodInfo); } } registry.Register(methods, methodsForType.Type); } return(registry); }
/// <summary> /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and automatically registers all types implementing <see cref="IExpressionNode"/> /// from a given type sequence that offer a public static <c>SupportedMethods</c> field. /// </summary> /// <returns>A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types with a <c>SupportedMethods</c> /// field registered.</returns> public static MethodInfoBasedNodeTypeRegistry CreateFromTypes (IEnumerable<Type> searchedTypes) { ArgumentUtility.CheckNotNull ("searchedTypes", searchedTypes); var expressionNodeTypes = from t in searchedTypes where typeof (IExpressionNode).IsAssignableFrom (t) select t; var supportedMethodsForTypes = from t in expressionNodeTypes let supportedMethodsField = t.GetField ("SupportedMethods", BindingFlags.Static | BindingFlags.Public) select new { Type = t, Methods = supportedMethodsField != null ? (IEnumerable<MethodInfo>) supportedMethodsField.GetValue (null) : Enumerable.Empty<MethodInfo>() }; var registry = new MethodInfoBasedNodeTypeRegistry(); foreach (var methodsForType in supportedMethodsForTypes) { List<MethodInfo> methods = new List<MethodInfo>(); foreach(var methodInfo in methodsForType.Methods) { if (methodInfo.DeclaringType.IsGenericType && !methodInfo.DeclaringType.IsGenericTypeDefinition) { var genericMethod = methodInfo.DeclaringType.GetGenericTypeDefinition().GetMethod(methodInfo.Name); methods.Add(genericMethod); } else { methods.Add(methodInfo); } } registry.Register (methods, methodsForType.Type); } return registry; }
public void SetUp () { _methodInfoBasedNodeTypeRegistry = MethodInfoBasedNodeTypeRegistry.CreateFromTypes (typeof(SelectExpressionNode).Assembly.GetTypes()); }
public void SetUp () { _registry = new MethodInfoBasedNodeTypeRegistry(); }
public void SetUp () { _methodInfoBasedNodeTypeRegistry = MethodInfoBasedNodeTypeRegistry.CreateFromRelinqAssembly(); }
public void VisitorUsesNodeTypeRegistry_ToParseAndAnalyzeSubQueries () { Expression subQuery = ExpressionHelper.MakeExpression (() => CustomSelect (ExpressionHelper.CreateQueryable<Cook>(), s => s)); Expression surroundingExpression = Expression.Lambda (subQuery); // evaluate the ExpressionHelper.CreateQueryable<Cook> () method var inputExpression = PartialEvaluatingExpressionVisitor.EvaluateIndependentSubtrees ( surroundingExpression, new TestEvaluatableExpressionFilter()); var emptyNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry(); emptyNodeTypeRegistry.Register (new[] { ((MethodCallExpression) subQuery).Method }, typeof (SelectExpressionNode)); var newLambdaExpression = (LambdaExpression) SubQueryFindingExpressionVisitor.Process (inputExpression, emptyNodeTypeRegistry); Assert.That (newLambdaExpression.Body, Is.InstanceOf (typeof (SubQueryExpression))); }
public void IntegrationTest_WithExpressionNodes () { var query = from a in ExpressionHelper.CreateQueryable<Cook> () from b in ExpressionHelper.CreateQueryable<Cook>() where a.ID > 5 select a.ID; var nodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry (); nodeTypeRegistry.Register (SelectExpressionNode.SupportedMethods, typeof (SelectExpressionNode)); nodeTypeRegistry.Register (SelectManyExpressionNode.SupportedMethods, typeof (SelectManyExpressionNode)); nodeTypeRegistry.Register (WhereExpressionNode.SupportedMethods, typeof (WhereExpressionNode)); var selectNode = (SelectExpressionNode) new ExpressionTreeParser (nodeTypeRegistry, new NullExpressionTreeProcessor()).ParseTree (query.Expression); var clauseGenerationContext = new ClauseGenerationContext (new MethodInfoBasedNodeTypeRegistry()); var selectManyNode = (SelectManyExpressionNode) selectNode.Source.Source; var mainSourceExpressionNode = (MainSourceExpressionNode) selectManyNode.Source; var queryModel = mainSourceExpressionNode.Apply (null, clauseGenerationContext); var mainFromClause = queryModel.MainFromClause; selectManyNode.Apply (queryModel, clauseGenerationContext); // only to add the clause to the mapping var selectProjection = selectNode.GetResolvedSelector (clauseGenerationContext); // new ( a = IR (a), b = IR (b) ).a.ID var result = TransparentIdentifierRemovingExpressionTreeVisitor.ReplaceTransparentIdentifiers (selectProjection); // IR(a).ID Assert.That (result, Is.InstanceOf (typeof (MemberExpression))); Expression innerExpression = ((MemberExpression)result).Expression; Assert.That (innerExpression, Is.InstanceOf (typeof (QuerySourceReferenceExpression))); Assert.That (((QuerySourceReferenceExpression) innerExpression).ReferencedQuerySource, Is.SameAs (mainFromClause)); }
private void AssertAllMethodsRegistered (MethodInfoBasedNodeTypeRegistry registry, Type type) { var supportedMethodsField = type.GetField ("SupportedMethods"); if (supportedMethodsField != null) { var methodInfos = (MethodInfo[]) supportedMethodsField.GetValue (null); Assert.That (methodInfos.Length, Is.GreaterThan (0)); foreach (var methodInfo in methodInfos) Assert.That (registry.GetNodeType (methodInfo), Is.SameAs (type)); } var supportedMethodNamesField = type.GetField ("SupportedMethodNames"); if (supportedMethodNamesField != null) { var methodNames = (string[]) supportedMethodNamesField.GetValue (null); Assert.That (methodNames.Length, Is.GreaterThan (0)); foreach (var methodName in methodNames) Assert.That (registry.GetNodeType (type.GetMethod (methodName)), Is.SameAs (type)); } }
public void Parse_WithSubQuery_UsesNodeTypeRegistry () { var emptyNodeTypeRegistry = new MethodInfoBasedNodeTypeRegistry (); emptyNodeTypeRegistry.Register (SelectExpressionNode.GetSupportedMethods(), typeof (SelectExpressionNode)); var parser = new MethodCallExpressionParser (emptyNodeTypeRegistry); var expression = (MethodCallExpression) ExpressionHelper.MakeExpression<IQueryable<Cook>, IQueryable<int>> ( q => q.Select (s => s.Assistants.Count ())); var result = parser.Parse ("t", _source, expression.Arguments.Skip (1), expression); Assert.That (result, Is.InstanceOf (typeof (SelectExpressionNode))); Assert.That (((SelectExpressionNode) result).Selector, Is.Not.TypeOf (typeof (SubQueryExpression)), "The given nodeTypeRegistry does not know any query methods, so no SubQueryExpression is generated."); }