Ejemplo n.º 1
0
        protected override Expression VisitMemberInit(MemberInitExpression node)
        {
            for (var bindingIndex = 0; bindingIndex < node.Bindings.Count; bindingIndex++)
            {
                var initExpressionBinding = node.Bindings[bindingIndex];
                if (initExpressionBinding.BindingType != MemberBindingType.Assignment)
                {
                    throw new NotSupportedException();
                }

                var memberAssignment = (MemberAssignment)initExpressionBinding;

                if (bindingIndex != 0)
                {
                    _statementBuilder.Append(",");
                    _statementBuilder.AppendLine();
                }

                var relationalPropertyAnnotations = _entityType.FindProperty(memberAssignment.Member.Name).Relational();

                var columnName = relationalPropertyAnnotations.ColumnName;
                _currentAssignmentColumnType = relationalPropertyAnnotations.ColumnType;

                _statementBuilder.Append("    ");
                _statementBuilder.DelimitIdentifier(columnName);
                _statementBuilder.Append(" = ");

                Visit(memberAssignment.Expression);
            }

            return(node);
        }
Ejemplo n.º 2
0
        public BulkQuery GetDeleteAllQuery <T>(DataContext dataContext)
        {
            var sqlProvider = dataContext.Vendor.SqlProvider;
            var rowType     = typeof(T);
            var table       = dataContext.Mapping.GetTable(rowType);

            var deleteBuilder = new SqlStatementBuilder("DELETE FROM ");

            deleteBuilder.Append(sqlProvider.GetTable(table.TableName));
            return(new BulkQuery {
                DataContext = dataContext, Sql = deleteBuilder.ToSqlStatement()
            });
        }
Ejemplo n.º 3
0
        public BulkQuery GetExistsQuery <T>(DataContext dataContext)
        {
            BulkQuery result = null;

            if (ExistsQueryCache.TryGetValue(typeof(T), out result))
            {
                if (result.DataContext == dataContext)
                {
                    return(result);
                }
            }

            var upsertParameters = GetUpsertParameters <T>(true, Columns <T>(), dataContext);
            var sqlProvider      = dataContext.Vendor.SqlProvider;
            var sqlBuilder       = new SqlStatementBuilder("SELECT COUNT (*) FROM ");

            sqlBuilder.Append(sqlProvider.GetTable(upsertParameters.Table.TableName));
            sqlBuilder.Append(" WHERE ");
            var valueSet = false;

            for (IEnumerator <SqlStatement> column = upsertParameters.InputPKColumns.GetEnumerator(), value = upsertParameters.InputPKValues.GetEnumerator(); column.MoveNext() && value.MoveNext();)
            {
                if (valueSet)
                {
                    sqlBuilder.Append(" AND ");
                }
                sqlBuilder.AppendFormat("{0} = {1}", column.Current, value.Current);
                valueSet = true;
            }

            result = new BulkQuery {
                DataContext          = dataContext,
                Sql                  = sqlBuilder.ToSqlStatement(),
                InputParameters      = upsertParameters.PKParameters,
                PrimaryKeyParameters = upsertParameters.PKParameters
            };
            ExistsQueryCache[typeof(T)] = result;
            return(result);
        }
Ejemplo n.º 4
0
        protected override Expression VisitNew(NewExpression node)
        {
            for (var argumentIndex = 0; argumentIndex < node.Arguments.Count; argumentIndex++)
            {
                var nodeArgument = node.Arguments[argumentIndex];

                if (argumentIndex != 0)
                {
                    _statementBuilder.Append(",");
                }

                Visit(nodeArgument);
            }

            return(node);
        }