public EntityContext Generate(SchemaSelector databaseSchema) { var entityContext = new EntityContext(); entityContext.DatabaseName = databaseSchema.Database.Name; string dataContextName = StringUtil.ToPascalCase(entityContext.DatabaseName) + "Context"; dataContextName = _namer.UniqueClassName(dataContextName); entityContext.ClassName = dataContextName; var tables = databaseSchema.Tables .Selected() .OrderBy(t => t.SortName) .ToTables(); foreach (TableSchema t in tables) { if (IsManyToMany(t)) { Debug.WriteLine("Many To Many Table: " + t.FullName); CreateManyToMany(entityContext, t); } else { Debug.WriteLine("Getting Table Schema: " + t.FullName); GetEntity(entityContext, t); } OnSchemaItemProcessed(t.FullName); } if (Settings.IncludeViews) { var views = databaseSchema.Views .Selected() .OrderBy(t => t.SortName) .ToViews(); foreach (ViewSchema v in views) { Debug.WriteLine("Getting View Schema: " + v.FullName); GetEntity(entityContext, v); OnSchemaItemProcessed(v.FullName); } } return(entityContext); }
//按表信息创建DbContext public EntityContext Generate(TableSchema tableSchema) { // only DeepLoad when in ignore mode tableSchema.DeepLoad = !Settings.InclusionMode; var entityContext = new EntityContext(); entityContext.DatabaseName = tableSchema.Database.Name; string dataContextName = StringUtil.ToPascalCase(tableSchema.Database.Name) + "Context"; dataContextName = _namer.UniqueClassName(dataContextName); entityContext.ClassName = dataContextName; GetEntity(entityContext, tableSchema); return(entityContext); }
public EntityContext Generate(DatabaseSchema databaseSchema) { // only DeepLoad when in ignore mode databaseSchema.DeepLoad = !Settings.InclusionMode; var entityContext = new EntityContext(); entityContext.DatabaseName = databaseSchema.Name; string dataContextName = StringUtil.ToPascalCase(databaseSchema.Name) + "Context"; dataContextName = _namer.UniqueClassName(dataContextName); entityContext.ClassName = dataContextName; foreach (TableSchema t in databaseSchema.Tables) { if (Settings.IsIgnored(t.FullName)) { Debug.WriteLine("Skipping Table: " + t.FullName); } else if (IsManyToMany(t)) { CreateManyToMany(entityContext, t); } else { Debug.WriteLine("Getting Table Schema: " + t.FullName); GetEntity(entityContext, t); } OnSchemaItemProcessed(t.FullName); } return(entityContext); }