Ejemplo n.º 1
0
        private void VisitInsertClause(Expression expression)
        {
            var listInit = expression as ListInitExpression
                           ?? throw new QueryException("Malformed insert expression");
            var insertedType  = VisitorParameters.TargetEntityType;
            var idents        = new List <HqlIdent>();
            var selectColumns = new List <HqlExpression>();

            //Extract the insert clause from the projected ListInit
            foreach (var assignment in listInit.Initializers)
            {
                var member = (ConstantExpression)assignment.Arguments[0];
                var value  = assignment.Arguments[1];

                //The target property
                idents.Add(_hqlTree.TreeBuilder.Ident((string)member.Value));

                var valueHql = HqlGeneratorExpressionVisitor.Visit(value, VisitorParameters).AsExpression();
                selectColumns.Add(valueHql);
            }

            //Add the insert clause ([INSERT INTO] insertedType (list of properties))
            _hqlTree.AddInsertClause(_hqlTree.TreeBuilder.Ident(insertedType.FullName),
                                     _hqlTree.TreeBuilder.Range(idents.ToArray()));

            //... and then the select clause
            _hqlTree.AddSelectClause(_hqlTree.TreeBuilder.Select(selectColumns));
        }
Ejemplo n.º 2
0
        private void VisitInsertClause(Expression expression)
        {
            var assignments = expression as BlockExpression
                              ?? throw new QueryException("Malformed insert expression");
            var insertedType  = VisitorParameters.TargetEntityType;
            var idents        = new List <HqlIdent>();
            var selectColumns = new List <HqlExpression>();

            //Extract the insert clause from the projected ListInit
            foreach (BinaryExpression assignment in assignments.Expressions)
            {
                var propName = ((ParameterExpression)assignment.Left).Name;
                var value    = assignment.Right;

                //The target property
                idents.Add(_hqlTree.TreeBuilder.Ident(propName));

                var valueHql = HqlGeneratorExpressionVisitor.Visit(value, VisitorParameters).AsExpression();
                selectColumns.Add(valueHql);
            }

            //Add the insert clause ([INSERT INTO] insertedType (list of properties))
            _hqlTree.AddInsertClause(_hqlTree.TreeBuilder.Ident(insertedType.FullName),
                                     _hqlTree.TreeBuilder.Range(idents.ToArray()));

            //... and then the select clause
            _hqlTree.AddSelectClause(_hqlTree.TreeBuilder.Select(selectColumns));
        }