Ejemplo n.º 1
0
 public void CreateDataModelFromTypes()
 {
     var model = AssemblyModelBuilder.GetDataModelFromTypes(new Type[]
     {
         typeof(Employee),
         typeof(ActionItem)
     }, "dbo", "Id");
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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"
            }));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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"
            }));
        }