protected override Expression VisitMember(MemberExpression m) { var source = Visit(m.Expression); IProperty property; // **fix** 解决无法返回两级以上关联对象的问题 // var ex = source as EntityExpression // if (ex != null && if ((property = PropertyUnity.GetProperty(m.Expression.Type, m.Member.Name)) != null && property is RelationProperty) { var projection = (ProjectionExpression)Visit(QueryUtility.GetMemberExpression(source, property)); if (currentFrom != null && m.Member.GetMemberType().GetEnumerableType() == null) { // convert singleton associations directly to OUTER APPLY projection = projection.AddOuterJoinTest(); var newFrom = new JoinExpression(JoinType.OuterApply, currentFrom, projection.Select, null); currentFrom = newFrom; return(projection.Projector); } return(projection); } var result = QueryBinder.BindMember(source, m.Member); if (result is MemberExpression mex && mex.Member == m.Member && mex.Expression == m.Expression) { return(m); } return(result); }
protected override Expression VisitBinary(BinaryExpression b) { var left = Visit(b.Left); var right = Visit(b.Right); if (left is NamedValueExpression nv0 && right is ColumnExpression c0) { left = QueryUtility.GetNamedValueExpression(nv0.Name, nv0.Value, (DbType)c0.MapInfo.DataType); }
protected override ColumnAssignment VisitColumnAssignment(ColumnAssignment ca) { ca = base.VisitColumnAssignment(ca); Expression expression = ca.Expression; if (expression is NamedValueExpression nv) { expression = QueryUtility.GetNamedValueExpression(nv.Name, nv.Value, (DbType)ca.Column.MapInfo.DataType); } return(this.UpdateColumnAssignment(ca, ca.Column, expression)); }
protected override Expression VisitEntity(EntityExpression entity) { var init = entity.Expression as MemberInitExpression; if (init != null) { var save = includeScope; includeScope = new ScopedDictionary <IProperty, bool>(this.includeScope); List <MemberBinding> newBindings = null; foreach (var property in PropertyUnity.GetRelatedProperties(entity.Type)) { PropertyInfo member; if (property is IPropertyLazy && policy.IsIncluded(member = property.Info.ReflectionInfo)) { if (includeScope.ContainsKey(property)) { throw new NotSupportedException(string.Format("Cannot include '{0}.{1}' recursively.", property.Type, property.Name)); } var me = QueryUtility.GetMemberExpression(init, property); if (newBindings == null) { newBindings = new List <MemberBinding>(init.Bindings); } newBindings.Add(Expression.Bind(member, me)); } } if (newBindings != null) { entity = new EntityExpression(entity.Metadata, Expression.MemberInit(init.NewExpression, newBindings)); } includeScope = save; } return(base.VisitEntity(entity)); }
protected override Expression VisitBinary(BinaryExpression b) { Expression left = this.Visit(b.Left); Expression right = this.Visit(b.Right); if (left.NodeType == (ExpressionType)DbExpressionType.NamedValue && right.NodeType == (ExpressionType)DbExpressionType.Column) { NamedValueExpression nv = (NamedValueExpression)left; ColumnExpression c = (ColumnExpression)right; left = QueryUtility.GetNamedValueExpression(nv.Name, nv.Value, (DbType)c.MapInfo.DataType); } else if (b.Right.NodeType == (ExpressionType)DbExpressionType.NamedValue && b.Left.NodeType == (ExpressionType)DbExpressionType.Column) { NamedValueExpression nv = (NamedValueExpression)right; ColumnExpression c = (ColumnExpression)left; right = QueryUtility.GetNamedValueExpression(nv.Name, nv.Value, (DbType)c.MapInfo.DataType); } return(b.Update(left, b.Conversion, right)); }