예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Procedure"/> class.
        /// </summary>
        /// <param name="prefix">The prefix used on stored procedure names.</param>
        public Procedure(dac.TSqlObject tSqlObject, string prefix, IEnumerable<dac.TSqlObject> primaryKeys, IDictionary<dac.TSqlObject, IEnumerable<ForeignKeyConstraintDefinition>> foreignKeys)
        {
            this.Prefix = prefix ?? "";
            this.RawName = tSqlObject.Name.Parts.Last();
            this.Name = this.RawName.Substring(this.Prefix.Length);
            this.Parameters = tSqlObject.GetReferenced(dac.Procedure.Parameters).Select(x => new Parameter(x, primaryKeys, foreignKeys));

            TSqlFragment fragment;
            TSqlModelUtils.TryGetFragmentForAnalysis(tSqlObject, out fragment);
            var selectVisitor = new SelectVisitor();
            fragment.Accept(selectVisitor);

            var bodyColumnTypes = tSqlObject.GetReferenced(dac.Procedure.BodyDependencies)
                .Where(x => x.ObjectType.Name == "Column")
                .GroupBy(bd => string.Join(".", bd.Name.Parts))
                .Select(grp => grp.First())
                .ToDictionary(
                    key => string.Join(".", key.Name.Parts),
                    val => new DataType
                    {
                        Map = DataTypeHelper.Instance.GetMap(TypeFormat.SqlServerDbType, val.GetReferenced(dac.Column.DataType).First().Name.Parts.Last()),
                        Nullable = dac.Column.Nullable.GetValue<bool>(val)
                    },
                    StringComparer.InvariantCultureIgnoreCase);

            var unions = selectVisitor.Nodes.OfType<BinaryQueryExpression>().Select(bq => GetQueryFromUnion(bq)).Where(x => x != null);
            var selects = selectVisitor.Nodes.OfType<QuerySpecification>().Concat(unions);

            this.Selects = selects.Select(s => new Select(s, bodyColumnTypes)).ToList();
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Table" /> class.
        /// </summary>
        /// <param name="tSqlObject">The TSqlObject representing the table.</param>
        /// <param name="primaryKeys">The primary keys.</param>
        /// <param name="foreignKeys">The foreign keys.</param>
        public Table(dac.TSqlObject tSqlObject, IEnumerable<dac.TSqlObject> primaryKeys, IDictionary<dac.TSqlObject, IEnumerable<ForeignKeyConstraintDefinition>> foreignKeys)
        {
            // Get the name.
            this.Name = tSqlObject.Name.Parts.Last();

            // Get the columns
            var columns = new List<Column>();
            var sqlColumns = tSqlObject.ObjectType.Name == "TableType" ? tSqlObject.GetReferenced(dac.TableType.Columns) : tSqlObject.GetReferenced(dac.Table.Columns);
            foreach (var sqlColumn in sqlColumns)
            {
                var column = new Column(sqlColumn, tSqlObject, primaryKeys, foreignKeys);
                columns.Add(column);
            }
            this.Columns = columns;
        }