public Entity.Metadata.Model SetTableNames(Entity.Metadata.Model model) { model.GetEntityType(typeof(Customer)).Relational().Table = "Customers"; model.GetEntityType(typeof(Employee)).Relational().Table = "Employees"; model.GetEntityType(typeof(Product)).Relational().Table = "Products"; model.GetEntityType(typeof(Order)).Relational().Table = "Orders"; model.GetEntityType(typeof(OrderDetail)).Relational().Table = "Order Details"; return(model); }
public void Generate_multiple_operations_batches_them_properly() { var model = new Entity.Metadata.Model(); var modelBuilder = new BasicModelBuilder(model); modelBuilder.Entity("Customer", b => { b.Property <string>("FirstName"); b.Property <string>("LastName"); b.ForRelational().Table("Customers", "dbo"); b.Key("FirstName", "LastName").ForRelational().Name("CustomerPK"); }); modelBuilder.Entity("Order", b => { b.Property <int>("Id"); b.Property <decimal?>("Quantity"); b.ForRelational().Table("Orders", "dbo"); b.Key("Id").ForRelational().Name("OrderPK"); }); var operations = new List <MigrationOperation> { new CreateDatabaseOperation("CustomeOrderDb"), OperationFactory().CreateTableOperation(model.GetEntityType("Customer")), OperationFactory().CreateTableOperation(model.GetEntityType("Order")), new DropDatabaseOperation("CustomeOrderDb"), }; var batches = SqlGenerator(model).Generate(operations).ToList(); Assert.Equal(1, batches.Count); Assert.Equal( @"CREATE DATABASE ""CustomeOrderDb""; CREATE TABLE ""dbo"".""Customers"" ( ""FirstName"" varchar(4000), ""LastName"" varchar(4000), CONSTRAINT ""CustomerPK"" PRIMARY KEY (""FirstName"", ""LastName"") ); CREATE TABLE ""dbo"".""Orders"" ( ""Id"" integer NOT NULL, ""Quantity"" decimal(18, 2), CONSTRAINT ""OrderPK"" PRIMARY KEY (""Id"") ); DROP DATABASE ""CustomeOrderDb""", batches[0].Sql); }
public void Generate_when_create_table_with_unique_constraints() { var model = new Entity.Metadata.Model(); var modelBuilder = new BasicModelBuilder(model); modelBuilder.Entity("E", b => { b.Property <int>("Foo").ForRelational().DefaultValue(5); var bar = b.Property <int?>("Bar").Metadata; var c1 = b.Property <string>("C1").Metadata; var c2 = b.Property <string>("C2").Metadata; b.ForRelational().Table("MyTable", "dbo"); b.Key("Foo").ForRelational().Name("MyPK"); b.Metadata.AddKey(c1).Relational().Name = "MyUC0"; b.Metadata.AddKey(new[] { bar, c2 }).Relational().Name = "MyUC1"; }); var operation = OperationFactory().CreateTableOperation(model.GetEntityType("E")); Assert.Equal( @"CREATE TABLE ""dbo"".""MyTable"" ( ""Foo"" integer NOT NULL DEFAULT 5, ""Bar"" integer, ""C1"" varchar(4000), ""C2"" varchar(4000), CONSTRAINT ""MyPK"" PRIMARY KEY (""Foo""), CONSTRAINT ""MyUC0"" UNIQUE (""C1""), CONSTRAINT ""MyUC1"" UNIQUE (""Bar"", ""C2"") )", Generate(operation, model)); }
public void Generate_when_add_column_operation() { var model = new Entity.Metadata.Model(); var modelBuilder = new BasicModelBuilder(model); modelBuilder.Entity("E", b => { b.Property <int>("Id"); b.Property <int>("Bar").ForRelational().DefaultValue(5); b.Key("Id"); b.ForRelational().Table("MyTable", "dbo"); }); var operation = new AddColumnOperation( "dbo.MyTable", OperationFactory().Column(model.GetEntityType("E").GetProperty("Bar"))); Assert.Equal( @"ALTER TABLE ""dbo"".""MyTable"" ADD ""Bar"" integer NOT NULL DEFAULT 5", Generate(operation, model)); }
public void Generate_when_alter_column_operation_with_nullable() { var model = new Entity.Metadata.Model(); var modelBuilder = new BasicModelBuilder(model); modelBuilder.Entity("E", b => { b.Property <int>("Id"); b.Property <int?>("Foo"); b.Key("Id"); b.ForRelational().Table("MyTable", "dbo"); }); var operation = new AlterColumnOperation( "dbo.MyTable", OperationFactory().Column(model.GetEntityType("E").GetProperty("Foo")), isDestructiveChange: false); Assert.Equal( @"ALTER TABLE ""dbo"".""MyTable"" ALTER COLUMN ""Foo"" integer NULL", Generate(operation, model)); }
public void Generate_when_create_table_operation() { var model = new Entity.Metadata.Model(); var modelBuilder = new BasicModelBuilder(model); modelBuilder.Entity("E", b => { b.Property <int>("Foo").ForRelational().DefaultValue(5); b.Property <int?>("Bar"); b.ForRelational().Table("MyTable", "dbo"); b.Key("Foo", "Bar").ForRelational().Name("MyPK"); }); var operation = OperationFactory().CreateTableOperation(model.GetEntityType("E")); Assert.Equal( @"CREATE TABLE ""dbo"".""MyTable"" ( ""Foo"" integer NOT NULL DEFAULT 5, ""Bar"" integer, CONSTRAINT ""MyPK"" PRIMARY KEY (""Foo"", ""Bar"") )", Generate(operation, model)); }