public InsertConsumerTest() { customerTable = new TableEntity("dbo", "Customer"); var customerId = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null); customerTable.AddColumn(customerId); customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerType", new ColumnDataTypeDefinition("int", false), false, 2, false, null, null)); customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Name", new ColumnDataTypeDefinition("varchar", false), false, 3, false, null, null)); customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("IsActive", new ColumnDataTypeDefinition("bit", false), false, 4, false, null, null)); orderTable = new TableEntity("dbo", "Orders"); orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null)); var fk = new ForeignKeyEntity(); fk.ReferencingColumn = "CustomerId"; fk.ReferencingTable = customerTable; var customerIdColumn = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), false, 2, true, null, fk); customerIdColumn.Generator = new SQLDataProducer.Entities.Generators.IntGenerators.ValueFromOtherColumnIntGenerator(customerIdColumn.ColumnDataType); customerIdColumn.Generator.GeneratorParameters.ValueFromOtherColumn.Value = customerId; orderTable.AddColumn(customerIdColumn); orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("ArticleId", new ColumnDataTypeDefinition("int", false), false, 3, false, null, null)); orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("TotalAmount", new ColumnDataTypeDefinition("decimal(19, 6)", false), false, 4, false, null, null)); var builder = new System.Data.SqlClient.SqlConnectionStringBuilder(); builder.DataSource = "localhost"; builder.InitialCatalog = "AdventureWorks"; builder.IntegratedSecurity = true; connectionString = builder.ToString(); }
public DataProducerTest() : base() { customerTable = new TableEntity("dbo", "Customer"); var customerId = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null); customerTable.AddColumn(customerId); customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("CustomerType", new ColumnDataTypeDefinition("int", false), false, 2, false, null, null)); customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Name", new ColumnDataTypeDefinition("varchar", true), false, 3, false, null, null)); customerTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("IsActive", new ColumnDataTypeDefinition("bit", true), false, 4, false, null, null)); var fk = new ForeignKeyEntity(); fk.ReferencingColumn = "CustomerId"; fk.ReferencingTable = customerTable; orderTable = new TableEntity("dbo", "Order"); var customerIdColumn = DatabaseEntityFactory.CreateColumnEntity("CustomerId", new ColumnDataTypeDefinition("int", false), false, 2, true, null, fk); customerIdColumn.Generator = new SQLDataProducer.Entities.Generators.IntGenerators.ValueFromOtherColumnIntGenerator(customerIdColumn.ColumnDataType); customerIdColumn.Generator.GeneratorParameters["Value From Column"].Value = customerId; orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("OrderId", new ColumnDataTypeDefinition("int", false), true, 1, false, null, null)); orderTable.AddColumn(customerIdColumn); orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("Amount", new ColumnDataTypeDefinition("decimal(19, 6)", false), false, 3, false, null, null)); orderTable.AddColumn(DatabaseEntityFactory.CreateColumnEntity("SessionId", new ColumnDataTypeDefinition("uniqueidentifier", false), false, 4, false, null, null)); }
public void ShouldCloneForeignKeyEntity() { ForeignKeyEntity foreignKey = new ForeignKeyEntity(); foreignKey.ReferencingColumn = "CustomerId"; foreignKey.ReferencingTable = new TableEntity("dbo", "Customer"); foreignKey.Keys.Add("Peter"); foreignKey.Keys.Add("Henell"); var cloned = foreignKey.Clone(); Assert.That(cloned.ReferencingColumn, Is.EqualTo(foreignKey.ReferencingColumn)); Assert.That(cloned.ReferencingTable, Is.EqualTo(foreignKey.ReferencingTable)); CollectionAssert.AreEqual(cloned.Keys, foreignKey.Keys); }
internal void Apply() { PrimaryKeyEntity.AddDependentRelationship( new EntityRelationship( Name, OnDeleteCascade, OnDeleteSetNull, ForeignKeyEntity, References.Select(r => new EntityReference(r.PrimaryKeyProperty, r.ForeignKeyProperty)))); ForeignKeyEntity.AddPrincipalRelationship( new EntityRelationship( Name, OnDeleteCascade, OnDeleteSetNull, PrimaryKeyEntity, References.Select(r => new EntityReference(r.ForeignKeyProperty, r.PrimaryKeyProperty)))); }
public static ColumnEntity CreateColumnEntity(string columnName, ColumnDataTypeDefinition columnDatatype, bool isIdentity, int ordinalPosition, bool isForeignKey, string constraintDefinition, ForeignKeyEntity foreignKeyEntity, string generatorName) { ColumnEntity c = new ColumnEntity(columnName, columnDatatype, isIdentity, ordinalPosition, isForeignKey, constraintDefinition, foreignKeyEntity); var gens = Generators.GeneratorFactory.GetGeneratorsForColumn(c); c.PossibleGenerators = gens; c.Generator = gens.Where(g => g.GeneratorName == generatorName).First(); return(c); }