public void GetTable_finds_table_by_name() { var database = new DatabaseModel(); var table0 = new Table("dbo.MyTable0"); var table1 = new Table("dbo.MyTable1"); database.AddTable(table0); database.AddTable(table1); Assert.Same(table0, database.GetTable("dbo.MyTable0")); Assert.Same(table1, database.GetTable("dbo.MyTable1")); }
private ForeignKey BuildForeignKey(DatabaseModel database, IForeignKey foreignKey) { Check.NotNull(foreignKey, "foreignKey"); var table = database.GetTable(GetSchemaQualifiedName(foreignKey.EntityType)); var referencedTable = database.GetTable(GetSchemaQualifiedName(foreignKey.ReferencedEntityType)); var columns = foreignKey.Properties.Select( p => table.GetColumn(p.ColumnName())).ToArray(); var referenceColumns = foreignKey.ReferencedProperties.Select( p => referencedTable.GetColumn(p.ColumnName())).ToArray(); var cascadeDelete = foreignKey.CascadeDelete(); var storeForeignKey = new ForeignKey( ForeignKeyName(foreignKey), columns, referenceColumns, cascadeDelete); table.AddForeignKey(storeForeignKey); return storeForeignKey; }
private static Index BuildIndex(DatabaseModel database, IIndex index) { Check.NotNull(index, "index"); var table = database.GetTable(GetSchemaQualifiedName(index.EntityType)); var columns = index.Properties.Select( p => table.GetColumn(p.ColumnName())).ToArray(); var storeIndex = new Index( IndexName(index), columns, index.IsUnique, index.IsClustered()); table.AddIndex(storeIndex); return storeIndex; }
private PrimaryKey BuildPrimaryKey(DatabaseModel database, IKey primaryKey) { Check.NotNull(primaryKey, "primaryKey"); var table = database.GetTable(GetSchemaQualifiedName(primaryKey.EntityType)); var columns = primaryKey.Properties.Select( p => table.GetColumn(p.ColumnName())).ToArray(); var isClustered = primaryKey.IsClustered(); table.PrimaryKey = new PrimaryKey(PrimaryKeyName(primaryKey), columns, isClustered); return table.PrimaryKey; }