Example #1
0
 public Database(string serverName, string catalogName, string systemSchema, IDynamicSchemaOptions schemaOptions, IEnumerable<Column> columns, IEnumerable<ColumnAssociation> associations, IEnumerable<Parameter> routineParameters, Database[] linkedDatabases)
 {
     this.Objects = new Dictionary<string, SchemaObject>();
     this.ServerName = serverName;
     this.CatalogName = catalogName;
     this.SystemSchema = systemSchema;
     this._schemaOptions = schemaOptions;
     this._columns = columns;
     this._associations = associations;
     this._routineParameters = routineParameters;
     this._linkedDatabases = linkedDatabases;
     this.LinkedDatabases = new Database[0];
     if (base.GetType() == typeof(Database))
     {
         this.Populate();
     }
 }
Example #2
0
 internal void AssignPropNames(Database db)
 {
     string str;
     if (this.IsOneToOne)
     {
         str = (this.ChildTable == this.ParentTable) ? "Child" : this.ChildTable.OriginalName;
     }
     else
     {
         str = (this.ChildTable == this.ParentTable) ? "Children" : this.ChildTable.PropertyName;
     }
     if (this.ParentCols.Count > 1)
     {
         this.PropNameForChild = this.ParentCols[0].ClrObjectName;
         this.PropNameForParent = str;
     }
     else
     {
         Column column = this.ChildCols[0];
         Column column2 = this.ParentCols[0];
         string str2 = (this.ParentTable.SingularName == null) ? this.ParentTable.DotNetName : this.ParentTable.SingularName;
         bool stripStem = true;
         this.PropNameForChild = StringUtil.StripTrailingKey(column.PropertyName, column2.PropertyName, true);
         if ((this.PropNameForChild.Length < 3) || (this.PropNameForChild.ToLowerInvariant() == "key"))
         {
             this.PropNameForChild = str2;
         }
         if (this.PropNameForChild == column.PropertyName)
         {
             this.PropNameForChild = this.PropNameForChild + (this.PropNameForChild.ToLowerInvariant().Contains(str2.ToLowerInvariant()) ? "Entity" : str2);
         }
         string identifier = StringUtil.GetDistinguishingIdentifier(column.PropertyName, this.ParentTable.DotNetName, column2.PropertyName, stripStem);
         identifier = db.TransformIdentifier(identifier);
         if (identifier.Length < 3)
         {
             identifier = "";
         }
         else if ((identifier.ToLowerInvariant() == "parent") && (str.ToLowerInvariant() == "children"))
         {
             identifier = "";
         }
         if ((identifier.Length > 4) && identifier.EndsWith("By", StringComparison.Ordinal))
         {
             identifier = StringUtil.StripTrailingWord(identifier, 2);
         }
         if ((this._allowOneToOne && (identifier.Length > 0)) && str.StartsWith(identifier, StringComparison.OrdinalIgnoreCase))
         {
             identifier = "";
         }
         this.PropNameForParent = identifier + str;
         if ((this.ChildTable != this.ParentTable) && this._allowOneToOne)
         {
             if (this.PropNameForChild == this.ChildTable.DotNetName)
             {
                 this.PropNameForChild = this.ParentTable.DotNetName;
             }
             if (this.PropNameForParent == this.ParentTable.DotNetName)
             {
                 this.PropNameForParent = this.ChildTable.DotNetName;
             }
         }
     }
 }
 public static void Generate(Database mainSchema, AssemblyName name, string cxString, string ns, string dataContextName)
 {
     string nsPrefix = string.IsNullOrEmpty(ns) ? "" : (ns + ".");
     string fileName = Path.GetFileName(name.CodeBase);
     AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Save, Path.GetDirectoryName(name.CodeBase));
     ModuleBuilder module = builder.DefineDynamicModule("MainModule", fileName, false);
     TypeBuilder type = module.DefineType(nsPrefix + dataContextName, TypeAttributes.Public, typeof(DataContextBase));
     EmitDataContextConstructors(type, cxString);
     new EmissionsGenerator(mainSchema).Generate(type, dotNetName => module.DefineType(nsPrefix + dotNetName, TypeAttributes.Public), null, null, null, null, null, mainSchema.LinkedDatabases.Length == 0);
     foreach (Database database in mainSchema.LinkedDatabases)
     {
         FieldBuilder dcField;
         TypeBuilder nestingContainer = module.DefineType(nsPrefix + database.ClrName + "Types", TypeAttributes.Public);
         TypeBuilder linkedClass = nestingContainer.DefineNestedType("TypedDataContext", TypeAttributes.NestedPublic);
         PopulateLinkedClass(linkedClass, type, database.ClrName, out dcField);
         new EmissionsGenerator(database).Generate(linkedClass, dotNetName => nestingContainer.DefineNestedType(dotNetName, TypeAttributes.NestedPublic), ilGen => ilGen.Emit(OpCodes.Ldfld, dcField), type, database.ClrName, database.ServerName, database.CatalogName, true);
         nestingContainer.CreateType();
     }
     type.CreateType();
     builder.Save(fileName);
 }
 private EmissionsGenerator(Database schema)
 {
     this.Schema = schema;
 }