public void FetchTests() { EzDbSchema.MsSql.Database dbschema = new EzDbSchema.MsSql.Database(); dbschema.Render("TestSchemaName", this.fixture.ConnectionString); foreach (var e in dbschema.Entities.Values) { try { var k1 = e.Relationships.Fetch(Core.Enums.RelationshipMultiplicityType.ManyToOne); var k2 = e.Relationships.Fetch(Core.Enums.RelationshipMultiplicityType.ManyToZeroOrOne); var k3 = e.Relationships.Fetch(Core.Enums.RelationshipMultiplicityType.OneToMany); var k4 = e.Relationships.Fetch(Core.Enums.RelationshipMultiplicityType.OneToOne); var k5 = e.Relationships.Fetch(Core.Enums.RelationshipMultiplicityType.ZeroOrOneToMany); } catch (Exception) { Assert.True(false, "Fetch calls failed"); } break; } Assert.True(dbschema.Entities.Count > 0, "No entites returned"); }
/* * Example Usage: -sc "Server=NSWIN10VM.local;Database=WideWorldImportersDW;user id=sa;password=sa" -sf "/Users/rvegajr/Downloads/Schema/WideWorldImportersDW.db.xml" -sn "WideWorldImportersDWEntities" */ public static void Enable(CommandLineApplication app) { app.ExtendedHelpText = "Used to read the Connection String frorm the App Settings file or use the command line to dump the schema file"; app.Description = "Perform actions on the schema ."; app.HelpOption("-?|-h|--help"); var verboseOption = app.Option("-verbose|--verbose", "Will display more detailed message about what is going on with the processing", CommandOptionType.NoValue); var schemaOutput = app.Option("-sf|--schema-filename <value>", "The file name or path to dump the schema to. This is required field.", CommandOptionType.SingleValue); var entityName = app.Option("-sn|--schema-name <value>", "The Name that will be given to the schema object. This value will override the value in appsettings.json. This is an optional field.", CommandOptionType.SingleValue); var connectionString = app.Option("-sc|--connection-string <optionvalue>", "Connection String pass via the commandline. This value will override the value in appsettings.json. This is an optional field.", CommandOptionType.SingleValue); var databaseType = app.Option("-db|--database-type <optionvalue>", "Optional switch to force the appication to process as a certain database type. This is an optional field. Default is auto, but can be set to 'mssql' or 'ora'.", CommandOptionType.SingleValue); app.OnExecute(() => { try { if (verboseOption.HasValue()) { AppSettings.Instance.VerboseMessages = verboseOption.HasValue(); } if (entityName.HasValue()) { AppSettings.Instance.SchemaName = entityName.Value(); } if (connectionString.HasValue()) { AppSettings.Instance.ConnectionString = connectionString.Value(); } var dbtype = (databaseType.HasValue() ? databaseType.Value() : "auto"); var outputPath = (schemaOutput.HasValue() ? schemaOutput.Value() : (@"{ASSEMBLY_PATH}" + AppSettings.Instance.SchemaName + @".db.xml").ResolvePathVars()); Console.WriteLine("Performing Schema Dump...."); Console.WriteLine("Connection String: " + AppSettings.Instance.ConnectionString); Console.WriteLine("Schema Name: " + AppSettings.Instance.SchemaName); Console.WriteLine("Output File/Path: " + outputPath); Console.WriteLine("Database Type: " + dbtype); IDatabase schemaObject = null; if ((AppSettings.Instance.ConnectionString.ToLower().Contains("database=")) || (dbtype.Equals("mssql"))) { Console.WriteLine("Processing a mssql database"); schemaObject = new EzDbSchema.MsSql.Database(); } else { throw new Exception(string.Format("Cannot figure out how to handle the connection string! '{0}'", AppSettings.Instance.ConnectionString)); } schemaObject.ShowWarnings = AppSettings.Instance.VerboseMessages; schemaObject = schemaObject.Render( AppSettings.Instance.SchemaName, AppSettings.Instance.ConnectionString); var schemaAsXml = schemaObject.AsXml(); File.WriteAllText(outputPath, schemaAsXml); Console.WriteLine(string.Format("Schema has been written to {0}", outputPath)); Console.WriteLine("Schema Dump has completed."); Environment.ExitCode = (int)ReturnCode.Ok; Environment.Exit(Environment.ExitCode); return(Environment.ExitCode); } catch (Exception ex) { Console.WriteLine(string.Format("{0} failed. {1}", "Schema Dump", ex.Message)); Console.WriteLine("Stack Trace:"); Console.WriteLine(ex.StackTrace); Environment.ExitCode = (int)ReturnCode.Error; Environment.Exit(Environment.ExitCode); return(Environment.ExitCode); } }); }