public void CreateDataModelFromTypes() { var model = AssemblyModelBuilder.GetDataModelFromTypes(new Type[] { typeof(Employee), typeof(ActionItem) }, "dbo", "Id"); }
public static async Task CreateTablesAsync(IEnumerable <Type> modelTypes, IDbConnection connection, SqlDialect dialect = null, string defaultSchema = "dbo", string defaultIdentityColumn = "Id") { var dataModel = AssemblyModelBuilder.GetDataModelFromTypes(modelTypes, defaultSchema, defaultIdentityColumn); if (dialect == null) { dialect = new SqlServerDialect(); } var script = await dataModel.ScriptCreateTablesAsync(connection, dialect); await dialect.ExecuteAsync(connection, script); }
public void InferFKWithoutReferencesAttr() { var model = AssemblyModelBuilder.GetDataModelFromTypes(new Type[] { typeof(Employee), typeof(ActionItem2) }, "dbo", "Id"); Assert.IsTrue(model.ForeignKeys.Contains(new ForeignKey() { Parent = new Table() { Name = "dbo.ActionItem2" }, Name = "FK_ActionItem2_EmployeeId" })); }
public void WriteJson() { var model = AssemblyModelBuilder.GetDataModelFromTypes(new Type[] { typeof(Employee), typeof(ActionItem2) }, "dbo", "Id"); Assert.IsTrue(model.ForeignKeys.Count() == 1); string fileName = GetFilename("sampleModel.json"); model.SaveJson(fileName); var load = DataModel.FromJsonFile(fileName); Assert.IsTrue(load.ForeignKeys.Count() == 1); }
public void VerifyTableNaming() { var dataModel = AssemblyModelBuilder.GetDataModelFromTypes(new Type[] { typeof(Employee), typeof(LogTable), typeof(UserProfile) }, "dbo", "Id"); Assert.IsTrue(dataModel.Tables.Contains(new Table() { Name = "dbo.Employee" })); Assert.IsTrue(dataModel.Tables.Contains(new Table() { Name = "log.LogTable" })); Assert.IsTrue(dataModel.Tables.Contains(new Table() { Name = "dbo.AspNetUsers" })); }