Exemplo n.º 1
0
 private void ReadRoutineParameters(IEnumerable <Parameter> routineParameters)
 {
     if (routineParameters != null)
     {
         SchemaObject obj2 = null;
         string       str  = null;
         foreach (Parameter parameter in routineParameters)
         {
             string key = parameter.RoutineSchema + "." + parameter.RoutineName;
             if (key != str)
             {
                 if (!this.Objects.TryGetValue(key, out obj2))
                 {
                     obj2 = null;
                 }
                 str = key;
             }
             if (obj2 != null)
             {
                 if (!parameter.IsValid)
                 {
                     this.Objects.Remove(key);
                 }
                 else if (parameter.IsResult)
                 {
                     obj2.ReturnInfo = parameter;
                 }
                 else
                 {
                     obj2.Parameters.Add(parameter);
                 }
             }
         }
         foreach (SchemaObject obj3 in this.Objects.Values)
         {
             DotNetNameBank bank = new DotNetNameBank();
             foreach (Parameter parameter2 in obj3.Parameters)
             {
                 bank.RegisterName(parameter2.ParamName);
             }
             foreach (Parameter parameter2 in obj3.Parameters.ToArray <Parameter>())
             {
                 string uniqueDotNetName = bank.GetUniqueDotNetName(parameter2.ParamName);
                 if (uniqueDotNetName == null)
                 {
                     obj2.Parameters.Remove(parameter2);
                 }
                 else
                 {
                     parameter2.ClrName = uniqueDotNetName;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 protected void Populate()
 {
     if (!this._populated)
     {
         this._populated = true;
         this.ReadColumns(this._columns);
         this.AssignColumnPropertyNames();
         this.ReadAssociations(this._associations);
         this.ReadRoutineParameters(this._routineParameters);
         HashSet <string> set  = new HashSet <string>(from o in this.Objects.Values select o.DotNetName);
         List <Database>  list = new List <Database>();
         if (this._linkedDatabases != null)
         {
             string[] source = (from db in this._linkedDatabases
                                where !string.IsNullOrEmpty(db.CatalogName)
                                group db by(db.SystemSchema == null) ? ((IEnumerable <string>)db.CatalogName) : ((IEnumerable <string>)db.SystemSchema) into g
                                where g.Count <Database>() > 1
                                select g.Key).ToArray <string>();
             foreach (Database database in this._linkedDatabases)
             {
                 if (database.SystemSchema != null)
                 {
                     database.ClrName = database.SystemSchema;
                 }
                 else
                 {
                     string str  = this.TransformIdentifier(database.ServerName);
                     string str3 = this.TransformIdentifier(database.CatalogName);
                     if (!(!source.Contains <string>(str3) || string.IsNullOrEmpty(str)))
                     {
                         str3 = str + "_" + str3;
                     }
                     database.ClrName = DotNetNameBank.ToDotNetName(str3);
                     if (!(string.IsNullOrEmpty(database.ClrName) || !set.Contains(database.ClrName)))
                     {
                         database.ClrName = database.ClrName + "Db";
                     }
                 }
                 if (!(string.IsNullOrEmpty(database.ClrName) || set.Contains(database.ClrName)))
                 {
                     list.Add(database);
                 }
             }
             this.LinkedDatabases = list.ToArray();
         }
     }
 }
Exemplo n.º 3
0
 private void AssignColumnPropertyNames()
 {
     foreach (SchemaObject obj2 in this.Objects.Values)
     {
         DotNetNameBank bank = new DotNetNameBank();
         foreach (Column column in obj2.Columns.Values)
         {
             bank.RegisterName(column.ColumnName);
         }
         HashSet <string> set = new HashSet <string>();
         foreach (Column column in obj2.Columns.Values.ToArray <Column>())
         {
             string uniqueDotNetName = bank.GetUniqueDotNetName(column.ColumnName);
             if (uniqueDotNetName == null)
             {
                 obj2.Columns.Remove(column.ColumnID);
             }
             else
             {
                 column.PropertyName = this.TransformIdentifier(uniqueDotNetName);
                 if (column.PropertyName == column.ClrObjectName)
                 {
                     if (bank.ContainsDotNetName("Content"))
                     {
                         obj2.Columns.Remove(column.ColumnID);
                     }
                     else
                     {
                         column.PropertyName = "Content";
                     }
                 }
                 if (set.Contains(column.PropertyName))
                 {
                     obj2.Columns.Remove(column.ColumnID);
                 }
                 else
                 {
                     set.Add(column.PropertyName);
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        private void ReadColumns(IEnumerable <Column> columns)
        {
            string str2;
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            List <Column> list = new List <Column>(0x1000);

            foreach (Column column in columns)
            {
                string str;
                list.Add(column);
                if (dictionary.TryGetValue(column.ObjectName, out str))
                {
                    if ((str != null) && (str != column.SchemaName))
                    {
                        dictionary[column.ObjectName] = null;
                    }
                }
                else
                {
                    dictionary.Add(column.ObjectName, column.SchemaName);
                }
            }
            DotNetNameBank bank = new DotNetNameBank();

            foreach (Column column in list)
            {
                str2 = dictionary[column.ObjectName];
                string sqlName = (((str2 != null) || (column.SchemaName == "dbo")) || (column.SchemaName == "")) ? column.ObjectName : (column.SchemaName + "_" + column.ObjectName);
                bank.RegisterName(sqlName);
            }
            HashSet <string> set = new HashSet <string>();

            foreach (Column column in list)
            {
                if (dictionary.TryGetValue(column.ObjectName, out str2))
                {
                    string str4             = (((str2 != null) || (column.SchemaName == "dbo")) || (column.SchemaName == "")) ? column.ObjectName : (column.SchemaName + "_" + column.ObjectName);
                    string uniqueDotNetName = bank.GetUniqueDotNetName(str4);
                    if (uniqueDotNetName != null)
                    {
                        if ((column.ObjectKind == DbObjectKind.Table) || (column.ObjectKind == DbObjectKind.View))
                        {
                            uniqueDotNetName = this.TransformIdentifier(uniqueDotNetName);
                        }
                        string key = column.SchemaName + "." + column.ObjectName;
                        if (!this.Objects.ContainsKey(key))
                        {
                            if (set.Contains(uniqueDotNetName))
                            {
                                continue;
                            }
                            set.Add(uniqueDotNetName);
                            SchemaObject obj2 = SchemaObject.Create(column, uniqueDotNetName);
                            this.Objects.Add(key, obj2);
                        }
                        SchemaObject obj3 = this.Objects[key];
                        if (column.IsKey)
                        {
                            obj3.HasKey = true;
                        }
                        column.ClrObjectName          = uniqueDotNetName;
                        column.Object                 = obj3;
                        obj3.Columns[column.ColumnID] = column;
                    }
                }
            }
            foreach (SchemaObject obj2 in this.Objects.Values)
            {
                obj2.OriginalName = obj2.PropertyName;
                if (this.Pluralize && obj2.IsPluralizable)
                {
                    string pluralName = StringUtil.GetPluralName(obj2.PropertyName);
                    if (!set.Contains(pluralName))
                    {
                        obj2.PropertyName = pluralName;
                    }
                }
            }
        }