public void SetConvertExpression( Type fromType, Type toType, LambdaExpression expr, bool addNullCheck = true) { if (fromType == null) { throw new ArgumentNullException("fromType"); } if (toType == null) { throw new ArgumentNullException("toType"); } if (expr == null) { throw new ArgumentNullException("expr"); } var ex = addNullCheck && expr.Find(Converter.IsDefaultValuePlaceHolder) == null? AddNullCheck(expr) : expr; Schemas[0].SetConvertInfo(fromType, toType, new ConvertInfo.LambdaInfo(ex, expr, null, false)); }
public SourceEntityConfiguration(string name, Type entityType, Func <QuerySource, IQueryable> queryFactory, Type joinKeyType, LambdaExpression localJoinExpression, LambdaExpression remoteJoinExpression) { Name = name; EntityType = entityType; if (queryFactory == null) { var param = Expression.Parameter(typeof(QuerySource)); QueryFactory = Expression.Lambda <Func <QuerySource, IQueryable> >(Expression.Call(param, _queryMethodInfo.MakeGenericMethod(entityType)), param).Compile(); } else { QueryFactory = queryFactory; } JoinKeyType = joinKeyType; LocalJoinExpression = localJoinExpression; RemoteJoinExpression = remoteJoinExpression; IEnumerable <string> dependencies = Enumerable.Empty <string>(); if (remoteJoinExpression != null) { var sourceParam = remoteJoinExpression.Parameters.First(); dependencies = remoteJoinExpression.Find <MemberExpression>(p => p.Expression == sourceParam) .Select(p => p.Member.Name); } DependsOn = ImmutableHashSet.Create <string>(dependencies.ToArray()); IsRootQuery = DependsOn.Count == 0; }
/// <summary> /// Adds an expression that converts a value of type <i>fromType</i> to <i>toType</i>. /// </summary> /// <param name="fromType">Type to convert from.</param> /// <param name="toType">Type to convert to.</param> /// <param name="expr">Expression to set.</param> /// <param name="addNullCheck">If <i>true</i>, adds an expression to check null value.</param> public void SetConvertExpression( [NotNull] Type fromType, [NotNull] Type toType, [NotNull] LambdaExpression expr, bool addNullCheck = true) { Code.NotNull(fromType, nameof(fromType)); Code.NotNull(toType, nameof(toType)); Code.NotNull(expr, nameof(expr)); var ex = addNullCheck && expr.Find(Converter.IsDefaultValuePlaceHolder) == null? AddNullCheck(expr) : expr; Schemas[0].SetConvertInfo(fromType, toType, new ConvertInfo.LambdaInfo(ex, expr, null, false)); }
public PropertyConfiguration(PropertyMetadata property, Func <string> label, bool canAggregate, bool canFilter, bool canSort, Func <object, LambdaExpression> customFilterExpression, LambdaExpression mappedExpression, bool calculcateDependencies = true) { Property = property; // TODO replace with propertyInfo from PropertyMetadata object PropertyInfo = property.Entity.ClrType.GetProperty(property.Name); Label = label; CanAggregate = canAggregate; CanFilter = canFilter; CanSort = canSort; CustomFilterExpression = customFilterExpression; MappedExpression = mappedExpression; List <string> members = new List <string>(); if (MappedExpression != null && calculcateDependencies) { var param = MappedExpression.Parameters.First(); members.AddRange(MappedExpression.Find <MemberExpression>(p => p.Expression == param).Select(p => p.Member.Name)); } DependsOn = ImmutableArray <string> .Empty.AddRange(members); }