public void TestMSIndexes_When_IndexExistsInBothAagAndAsysIndex_Then_OnlyAAgAdded() { TestIndexes_When_IndexExistsInBothAagAndAsysIndex_Then_OnlyAAgAdded(); DbSchema.IsIndex("i_" + TestTable, TestTable).Should().BeTrue("because index should exists"); DbSchema.IsIndex("i_" + TestTable + "1", TestTable).Should().BeFalse("because index should only exist when running Sql Server"); }
public CloneDatabaseProgressForm(SqlAgentBase sourceAgent, SqlAgentBase targetAgent, DbSchema schema) { InitializeComponent(); _sourceAgent = sourceAgent; _targetAgent = targetAgent; _schema = schema; }
public void RequestHashIsValueBased() { var table = new Table() { Name = "tbl1", Schema = "sch1" }; var view = new View() { Name = "vw1", Schema = "sch1" }; var proc = new StoredProcedure() { Name = "proc1", Schema = "sch1" }; var schema = new DbSchema(); schema.Tables.Add(table); schema.Views.Add(view); schema.StoredProcedures.Add(proc); var schema2 = new DbSchema(); schema2.Tables.Add(table); schema2.Views.Add(view); schema2.StoredProcedures.Add(proc); Assert.AreEqual(schema.GetHashCode(), schema2.GetHashCode()); }
public static string getConnectionString(DbSchema dbSchema) { var dic = conStrLoader.conStrDic; string ret = String.Empty; dic.TryGetValue(dbSchema.ToString(), out ret); return ret; }
public async Task <ComplexityWarningState> GetOrCreate(string accountId, Func <ComplexityWarningState> factory) { await using var conn = new SqlConnection(_connectionString); var existed = await conn.GetAsync <DbSchema>(accountId); if (existed != null) { return(existed.ToDomain()); } var newItem = DbSchema.FromDomain(factory()); try { await conn.InsertAsync(newItem); } catch (SqlException e) when(e.Number == 2627 || e.Number == 2601) // unique constraint violation { await _log.WriteWarningAsync(nameof(ComplexityWarningRepository), nameof(GetOrCreate), $"Optimistic concurrency control violated: Entity with id {accountId} already exists, use that value"); } return((await conn.GetAsync <DbSchema>(accountId)).ToDomain()); }
private int _top; // top N records #endregion Fields #region Constructors /// <summary> /// Initializes a new instance of a <see cref="QueryBuilder"/>. /// </summary> /// <param name="schema"><see cref="OleDbSchema"/> used by the query builder.</param> public QueryBuilder(DbSchema schema) { _sql = null; _schema = schema; _queryFields = new QueryFieldCollection(); _queryFields.CollectionChanged += _queryFields_ListChanged; }
/// <summary> /// Constructor /// </summary> /// <param name="connectionString">Full connection string</param> /// <param name="dataBaseTypes">The type of the database Ms-sql or Sql-light</param> public Transaction(string connectionString, DataBaseTypes dataBaseTypes) : base() { base._transaction = this; _attachedObjects = new Custom_ValueType <string, object>(); if (string.IsNullOrEmpty(connectionString)) { if (string.IsNullOrEmpty(connectionString)) { throw new EntityException("ConnectionString can not be empty"); } } ConnectionString = connectionString; DataBaseTypes = dataBaseTypes; _dbSchema = new DbSchema(this); if (!_moduleIni[dataBaseTypes]) { lock (this) { if (!_moduleIni[dataBaseTypes]) { OnModuleConfiguration(new ModuleBuilder(dataBaseTypes)); OnModuleStart(); _moduleIni[dataBaseTypes] = true; } } } else { _moduleIni[dataBaseTypes] = true; } }
public JsonRepository(NpgsqlConnection connection, IJsonTypeValidator typeValidator = null) { Connection = connection; Schema = new DbSchema(connection.ConnectionString); TypeValidator = typeValidator ?? new JsonTypeValidator(); Connection.OpenAsync().Wait(); }
public void CreateLoadTableText(ConvertDbFtoSql xamlconvert) { UpdateModel modelupdate = new UpdateModel(); modelupdate.UpdateModelProgressBarProgress(xamlconvert); float proc = 100.0f / xamlconvert.ListViewDbfView.Dispatcher.Invoke(() => xamlconvert.ListViewDbfView.SelectedItems.Count); if (xamlconvert.ListViewDbfView != null) { foreach (Dbf shema in xamlconvert.ListViewDbfView.Dispatcher.Invoke(() => xamlconvert.ListViewDbfView.SelectedItems)) { try { modelupdate.UpdateModelProgressBarProgress(xamlconvert, shema.NameTable, proc); DbSchema shem = new DbSchema(ConectionString.ConectString.SqlConection, DbPlatform.SqlServer2008); shem.Alter(basetable => Logic.LogicApplication.CreateTableSql(basetable, shema)); Logic.LogicApplication.SaveContentsToSqlTable(shema); } catch (Exception exception) { MessageBox.Show(exception.Message); } } } modelupdate.UpdateModelProgressBarProgress(xamlconvert); }
public DbSchema GetSchema() { var schema = new DbSchema(); var map = _configuration.BuildMapping(); var mappings = _configuration.ClassMappings; foreach(var class_map in mappings) { var table = class_map.Table; var table_schema = new TableSchema() {TableName = table.Name, SchemaName = table.Schema}; foreach (var column in table.ColumnIterator) { var type_code = column.GetSqlTypeCode(map); var columnSchema = new ColumnSchema() { TableName = table_schema.TableName, ColumnName = column.Name, IsNullable = column.IsNullable, DatabaseType = type_code.DbType, Size = column.Length, Scale = column.Scale, Precision = column.Precision, IsPrimaryKey = table.PrimaryKey.Columns.Contains(column) }; // columnSchema.DatabaseType = property.GetSqlTypeCode(map).DbType; table_schema.AddColumn(columnSchema); } schema.AddTable(table_schema); } return schema; }
public void Open(string filePath) { if (filePath.IsNullOrWhiteSpace()) { return; } if (!SaveCurrentSource()) { return; } var result = new DbSchema(); try { result.LoadXmlFile(filePath); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } RebindDataSource(result); _currentFilePath = filePath; this.Text = "Database Schema: " + _currentFilePath; }
/// <summary> /// select object by its id /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="objectId"></param> /// <returns></returns> public static ISqlQueriable <T> GetAbstractById <T>(this ICustomRepository repository, long?objectId) where T : class, IDbEntity { return(!objectId.HasValue ? null : new SqlQueriable <T>(new List <T>() { (T)DbSchema.GetSqlById(objectId.Value, repository, typeof(T)) }, repository)); }
public void SchemaTestMethod() { var pms = new NameValueList(); pms.Add(""); var schema = new DbSchema(DbProvider.Initialize(pms)); }
public void FetchSchema(DbConnection connection) { var dbObjects = _utils.GetDbObjects(connection.DatabaseType, connection.ConnectionString, false); var dbObjectProperties = _utils.GetDbObjectProperties(connection.DatabaseType, connection.ConnectionString); var dbSchemas = new Dictionary <string, DbSchema>(); foreach (var dbObject in dbObjects) { dbObject.Connection = connection; Create <DbObject>(dbObject); if (!dbSchemas.ContainsKey(dbObject.SchemaName)) { var schema = new DbSchema() { Connection = connection, Name = dbObject.SchemaName /*, Objects = new List<DbObject>()*/ }; dbSchemas.Add(dbObject.SchemaName, schema); } } foreach (var dbObjectProperty in dbObjectProperties) { dbObjectProperty.Connection = connection; Create <DbObjectProperty>(dbObjectProperty); } foreach (var dbSchema in dbSchemas.Values) { Create <DbSchema>(dbSchema); } }
private void SchemasList_SelectedIndexChanged(object sender, EventArgs e) { using (new WaitCursor(this)) { TablesList.Items.Clear(); if (SchemasList.SelectedItems.Count > 0) { DbSchema schema = (DbSchema)SchemasList.SelectedItems[0].Tag; SetSelection(schema); foreach (DbTable item in this.provider.GetTables(schema)) { ListViewItem lvi = TablesList.Items.Add(item.Name, 2); lvi.Tag = item; if (item.IsView) { lvi.Group = TablesList.Groups["Views"]; } else { lvi.Group = TablesList.Groups["Tables"]; } } } TablesList.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); } }
/// <summary> /// 加载数据表 /// </summary> /// <param name="connectionName"></param> private void LoadTable(String connectionName) { // 加载数据库 nowConnectionName = connectionName; var dal = new DbConnConfigDAL(); var model = dal.FindOne(connectionName); this.nowDbSchema = DbSchemaFactory.Create(new MySqlDatabase(model.ConnectionString, MySqlClientFactory.Instance)); try { nowDb = this.nowDbSchema.GetDatabase(model.DefaultDb); } catch (Exception e1) { MsgBox.ShowErrorMessage("数据库打开失败:" + e1.Message); return; } // 加载表 this.listBox1.Items.Clear(); this.listBox2.Items.Clear(); this.unSelectedTableList.Clear(); this.selectedTableList.Clear(); foreach (SOTable t in nowDb.TableList) { listBox1.Items.Add(t); unSelectedTableList.Add(t); } }
public void TestOraIndexes_When_IndexExistsInAsysIndex() { TestIndexes_When_IndexExistsInAsysIndex(); DbSchema.IsIndex("i_" + TestTable, TestTable).Should().BeTrue("because index should exists"); DbSchema.IsIndex("i_" + TestTable + "1", TestTable).Should().BeTrue("because additional index exists in asysIndex and we are running Oracle"); }
public void TestOraIndexes_When_IndexExistsInBothAagAndAsysIndex_Then_OnlyAAgAdded() { TestIndexes_When_IndexExistsInBothAagAndAsysIndex_Then_OnlyAAgAdded(); DbSchema.IsIndex("i_" + TestTable, TestTable).Should().BeTrue("because index should exists"); DbSchema.IsIndex("i_" + TestTable + "1", TestTable).Should().BeTrue("because additional index exists when running Oracle"); }
private GroupByExtension _gbExtension; // cube/rollup/all #endregion //---------------------------------------------------------------- #region Constructors /// <summary> /// Initializes a new instance of a <see cref="QueryBuilder"/>. /// </summary> /// <param name="schema"><see cref="OleDbSchema"/> used by the query builder.</param> public QueryBuilder(DbSchema schema) { _sql = null; _schema = schema; _queryFields = new QueryFieldCollection(); _queryFields.CollectionChanged += _queryFields_ListChanged; }
public List <IDbEntity> GetAllTables(DbSchema schema, IDbConnection conn = null) { using (var con = conn ?? GetConnection()) { return(con.Query <DbEntity>(SqlStatements.GetAllTables(_dbType), new { DbName = con.Database, Schema = schema.SchemaName }).ToList <IDbEntity>()); } }
public override void Cleanup() { base.Cleanup(); DbSchema.DropView(Testview); DbSchema.DropTable(Asysview); DbSchema.DropTable(Aagview); }
// build the SELECT clause string BuildSelectClause() { StringBuilder sb = new StringBuilder(); foreach (QueryField field in QueryFields) { if (field.Output) { // add separator if (sb.Length > 0) { sb.Append(",\r\n\t"); } // add field expression ("table.column" or "colexpr") string item = field.GetFullName(GroupBy); sb.Append(item); // add alias (use brackets to contain spaces, reserved words, etc) if (!string.IsNullOrEmpty(field.Alias)) { sb.AppendFormat(" AS {0}", DbSchema.BracketName(field.Alias)); } } } return(sb.ToString()); }
/// <summary> /// Executes the query. /// </summary> /// <returns> /// The number of rows affected. /// </returns> public override int ExecuteNonQuery() { // Source: //// http://regexadvice.com/forums/thread/55175.aspx Regex regex = new Regex(@"CREATE *SCHEMA *\((.*)\)"); var matches = regex.Matches(this.CommandText.Trim()); if (matches.Count != 1) { throw new NotSupportedException(); } string keyString = matches[0].Groups[1].Value; DbSchemaKey key = DbSchemaKey.FromString(keyString); DbSchema schema = DbSchemaStore.GetDbSchema(key); DbContainer container = this.EffortConnection.DbContainer; container.Initialize(schema); return(0); }
private void ReadAndVerify( string expectedType, int?expectedLength, int?expectedPrec, int?expectedScale) { _reader.Read(new List <string>() { TableName }, out int tableCounter, out int errorCounter); DbSchema.GetRawColumnDefinition(TableName, "col1", out string type, out int length, out int prec, out int scale); type.ToLower().Should().Be(expectedType); if (expectedLength.HasValue) { length.Should().Be(expectedLength.Value); } if (expectedPrec.HasValue) { prec.Should().Be(expectedPrec.Value); } if (expectedScale.HasValue) { scale.Should().Be(expectedScale.Value); } }
/// <summary> /// Delete object from db /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="o"></param> internal static async Task DeleteAbstractAsync <T>(this ICustomRepository repository, T o) where T : class, IDbEntity { if (o != null) { await Task.Run(() => DbSchema.DeleteAbstract(repository, o, true)); } }
private void btnQuery_Click(object sender, EventArgs e) { if (cbConnectionStrings.SelectedItem == null) { return; } string cnName = cbConnectionStrings.SelectedItem.ToString(); DbSchema schema = DbSchemaFactory.Create(cnName); string schemaName = cbSchemaName.SelectedItem == null ? cbSchemaName.Text : cbSchemaName.SelectedItem.ToString(); string s = txtRestrictions.Text; DataTable dt; if (s == string.Empty) { dt = schema.GetSchema(schemaName); } else { string[] restrictions = s.Split(','); dt = schema.GetSchema(schemaName, restrictions); } gridView.DataSource = dt; }
public static void UpdateTable(string connString, string dbName) { var schema = new DbSchema(connString); _builder = new BuilderBL.SQLDesigner.QueryBuilder(schema); var newGroup = new Group { Name = dbName, SubGroups = new List <Group>(), Entries = new List <Entry>() }; if (schema != null) { foreach (var dt in schema.GetTableEntities(schema)) { var temp = new Group { Name = dt.Key, SubGroups = new List <Group>(), Entries = new List <Entry>() }; foreach (var entry in dt.Value) { temp.Entries.Add(new Entry() { Name = entry, Parent = dt.Key }); } newGroup.SubGroups.Add(temp); } MainWindowData.UserConnections.Add(newGroup); } }
/// <summary> /// A method that should do the actual new database creation. /// </summary> /// <param name="dbSchema">a DbSchema to use for the new database</param> /// <remarks>After creating a new database the <see cref="SqlAgentBase.CurrentDatabase">CurrentDatabase</see> /// property should be set to the new database name.</remarks> /// <exception cref="ArgumentException">Database schema should contain at least one table.</exception> public override Task CreateDatabaseAsync(DbSchema dbSchema) { if (dbSchema.IsNull()) { throw new ArgumentNullException(nameof(dbSchema)); } if (Agent.IsTransactionInProgress) { throw new InvalidOperationException(Properties.Resources.CreateDatabaseExceptionTransactionInProgress); } if (dbSchema.Tables.Count < 1) { throw new ArgumentException(Properties.Resources.DatabaseCreateExceptionNoTables, nameof(dbSchema)); } if (!dbSchema.AllIndexesUnique()) { dbSchema.SetSafeIndexNames(); } var script = dbSchema.GetTablesInCreateOrder().Aggregate(new List <string>(), (seed, table) => { seed.AddRange(table.GetCreateTableStatements(MyAgent)); return(seed); }); return(Agent.ExecuteCommandBatchAsync(script.ToArray())); }
public static string GenerateCode(ClrClass @class, DbTable table, DbSchema schema) { if (@class == null) { throw new ArgumentNullException("class"); } if (table == null) { throw new ArgumentNullException("table"); } if (schema == null) { throw new ArgumentNullException("schema"); } var foreignKeyTables = ForeignKeyHelper.GetForeignKeyTables(table.Columns, schema); if (table.IsReadOnly) { return(GetAdapterReadonOnly(@class, table, foreignKeyTables)); } var collectionType = ClrTypeHelper.GetCollectionType(@class.Properties); if (collectionType == null) { return(GetAdapter(@class, table, foreignKeyTables)); } return(GetAdapterWithCollection(@class, table, foreignKeyTables, FindCollectionTable(schema, collectionType))); }
public DbSchema GetSchema(DatabaseConnectionInfo connectionInfo) { var dbObjects = new List <DbSchemaObject>(); var tables = GetTables(connectionInfo); foreach (var dbObject in tables.Values) { dbObjects.Add(dbObject); } var modules = GetModules(connectionInfo); foreach (var dbObject in modules) { dbObjects.Add(dbObject); } var fkeys = GetForeignKeys(connectionInfo); foreach (var dbObject in fkeys) { dbObjects.Add(dbObject); } var schema = new DbSchema(dbObjects); return(schema); }
/// <summary> /// Delete object from db /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repository"></param> /// <param name="o"></param> internal static void DeleteAbstract <T>(this ICustomRepository repository, T o) where T : class, IDbEntity { if (o != null) { DbSchema.DeleteAbstract(repository, o, true); } }
public void TestOraIndexes_When_IndexExistsInAsysIndex_But_U4IndexesIsNotSet() { TestIndexes_When_IndexExistsInAsysIndex_But_U4IndexesIsNotSet(); DbSchema.IsIndex("i_" + TestTable, TestTable).Should().BeTrue("because index should exists"); DbSchema.IsIndex("i_" + TestTable + "1", TestTable).Should().BeFalse("because additional indexex in asysIndex are ignored, and we are running Oracle"); }
private void RebindDataSource(DbSchema newSource) { this.dbSchemaBindingSource.RaiseListChangedEvents = false; this.tablesBindingSource.RaiseListChangedEvents = false; this.fieldsBindingSource.RaiseListChangedEvents = false; UnbindBindingSource(fieldsBindingSource); UnbindBindingSource(tablesBindingSource); UnbindBindingSource(dbSchemaBindingSource); this.fieldsBindingSource.EndEdit(); this.tablesBindingSource.EndEdit(); this.dbSchemaBindingSource.EndEdit(); this.dbSchemaBindingSource.DataSource = null; _currentSource = newSource; this.fieldsBindingSource.DataSource = this.tablesBindingSource; this.tablesBindingSource.DataSource = this.dbSchemaBindingSource; this.dbSchemaBindingSource.DataSource = _currentSource; this.dbSchemaBindingSource.RaiseListChangedEvents = true; this.tablesBindingSource.RaiseListChangedEvents = true; this.fieldsBindingSource.RaiseListChangedEvents = true; this.fieldsBindingSource.ResetBindings(false); this.tablesBindingSource.ResetBindings(false); this.dbSchemaBindingSource.ResetBindings(false); this.tablesDataGridView.Select(); }
public SchemaRelation(DbSchema schema, SchemaTable parentTable, SchemaTable childTable, IEnumerable<SchemaColumn> parentColumns, IEnumerable<SchemaColumn> childColumns, string relationName = null, bool isOneToOne = false, bool isRequired = true, bool isReversed = false) { Schema = schema; ParentTable = parentTable; ChildTable = childTable; ParentColumns = new ReadOnlyObservableCollection<SchemaColumn>(new ObservableCollection<SchemaColumn>(parentColumns)); ChildColumns = new ReadOnlyObservableCollection<SchemaColumn>(new ObservableCollection<SchemaColumn>(childColumns)); RelationName = String.IsNullOrWhiteSpace(relationName) ? String.Format("{0}_{1}", parentTable.TableName, childTable.TableName) : relationName; RelationType = isOneToOne ? RelationType.OneToOne : RelationType.OneToMany; IsRequired = isRequired; IsReversed = isReversed; }
private IList<DbTable> GetTables() { using (Context.Development) { var config = Simply.Do.GetConfig<ApplicationConfig>(); var db = new DbSchema(config.ADOProvider, Simply.Do.GetConnectionString()); var names = new TableNameTransformer(Options.Do.TableNames).Transform(TableNames); var ret = db.GetTables(names.Included, names.Excluded).ToList(); Simply.Do.Log(this).InfoFormat("Found tables: {0}", string.Join(", ", ret.Select(x => x.Name).ToArray())); return ret; } }
protected override DbSchema GetSchema() { if (schema == null) { schema = new DbSchema("QFPrikazVyskladDetail"); schema.Add("IDPrikazVYskladDetail", typeof(int), "IDPrikazVYskladDetail", false, true, true); schema.Add("PrikazVyskladID", typeof(int), "PrikazVyskladID", false, true, false); schema.Add("ComponentID", typeof(int), "ComponentID", true); schema.Add("DescriptionPDM", typeof(string), "DescriptionPDM", true); schema.Add("Qty", typeof(int), "Qty", true); //added schema.Add("BIN", typeof(int), "BIN", true); schema.Add("EOD", typeof(int), "EOD", true); schema.Add("PcsBIN", typeof(int), "PcsBIN", true); schema.Add("DescriptionComp", typeof(int), "DescriptionComp", true); schema.Add("ReasonSubst", typeof(int), "ReasonSubst", true); schema.Add("UnitWeight", typeof(int), "UnitWeight", true); schema.Add("TotalWeight", typeof(int), "TotalWeight", true); } return schema; }
protected override DbSchema GetSchema() { if (schema == null) { schema = new DbSchema("QFComponentsPhoto"); schema.Add("ComponentID", typeof(int), "ComponentID", false, true, true); schema.Add("Code", typeof(string), "Code", false); schema.Add("Vendor", typeof(string), "Vendor", true); schema.Add("Description", typeof(string), "Description", true); //schema.Add("ProdApprovPDM", typeof(DateTime), "ProdApprovPDM", true); schema.Add("PDMStatusPhotoID", typeof(int), "PDMStatusPhotoID", true); schema.Add("KategorieKomponentu", typeof(string), "KategorieKomponentu", true); schema.Add("PDMComent", typeof(string), "PDMComent", true); schema.Add("Note", typeof(string), "Note", true); schema.Add("SpecialNote", typeof(string), "SpecialNote", true); schema.Add("BIN", typeof(string), "BIN", true); schema.Add("PcsBIN", typeof(string), "PcsBIN", true); schema.Add("VP", typeof(int), "VP", true); schema.Add("KomponentKategorieID", typeof(int), "KomponentKategorieID", true); schema.Add("FyzickaKontrola", typeof(int), "FyzickaKontrola", true); schema.Add("VzorovyKomponent", typeof(int), "VzorovyKomponent", true); schema.Add("NafocenoKdy", typeof(DateTime), "NafocenoKdy", true); schema.Add("NafotilKdoID", typeof(int), "NafotilKdoID", true); schema.Add("Pcs", typeof(int), "Pcs", true); schema.Add("DostupnostID", typeof(int), "DostupnostID", true); schema.Add("PohledT", typeof(int), "PohledT", true); schema.Add("PohledTF", typeof(int), "PohledTF", true); schema.Add("PohledC", typeof(int), "PohledC", true); schema.Add("PohledSpecial", typeof(int), "PohledSpecial", true); schema.Add("PohledCompics", typeof(int), "PohledCompics", true); schema.Add("KontrolaFotek", typeof(int), "KontrolaFotek", true); schema.Add("Kprefoceni", typeof(int), "Kprefoceni", true); schema.Add("EOD", typeof(string), "EOD", true); schema.Add("SCRAP", typeof(int), "SCRAP", true); schema.Add("SCRAPdate", typeof(DateTime), "SCRAPdate", true); schema.Add("New", typeof(bool), "New", false); schema.Add("ReasonSubst", typeof(string), "ReasonSubst", true); schema.Add("VendorPhoto", typeof(string), "VendorPhoto", true); schema.Add("ZmenaDesignu", typeof(bool), "ZmenaDesignu", false); schema.Add("ZmenaDatum", typeof(DateTime), "ZmenaDatum", true); schema.Add("ZmenaPozn", typeof(string), "ZmenaPozn", true); schema.Add("Vaha", typeof(decimal), "Vaha", true); schema.Add("VahaPoznamka", typeof(string), "VahaPoznamka", true); schema.Add("TimeRevision", typeof(bool), "TimeRevision", false); schema.Add("PcsBIN2", typeof(int), "PcsBIN2", true); // added schema.Add("AvailabilityName", typeof(string), "AvailabilityName", true); schema.Add("NafotilKdoStr", typeof(string), "NafotilKdoStr", true); schema.Add("PDMStatusPhoto", typeof(string), "PDMStatusPhoto", true); schema.Add("KomponentKategorieName", typeof(string), "KomponentKategorieName", true); } return schema; }
public void TestDbSchemaAltering() { Migrator migrator = CreateMigrator(); // verify if the migrations batch is populated correctly IMigrationBatch batch = migrator.FetchMigrationsTo(typeof(Migration1).Assembly, Timestamps[0]); Assert.AreEqual(1, batch.Steps.Count); CollectionAssert.AreEqual(new[] { Timestamps[0] }, batch.Steps[0].Migrations.Select(m => m.Timestamp).ToArray()); Assert.AreEqual(MigrationExportAttribute.DefaultModuleName, batch.Steps[0].ModuleName); Assert.IsNull(batch.Steps[0].Migrations.Single().Tag); Assert.AreEqual(MigrationDirection.Up, batch.Steps[0].Direction); // use MigrateTo to execute the actual migrations to test that method, too migrator.MigrateTo(typeof(Migration1).Assembly, Timestamps[0]); CheckResultsOfMigration1(); // execute a DB altering operation outside of any versioning var dbSchema = new DbSchema(ConnectionString, DbPlatform); if (CustomConnection != null) { dbSchema.UseCustomConnection(CustomConnection); } const string tableName = "Non-versioned Table"; dbSchema.Alter(db => db.CreateTable(tableName) .WithPrimaryKeyColumn("Id", DbType.Int32)); // assert table was created DataTable bypassTable = GetTable(new TableName(tableName, null)); Assert.IsNotNull(bypassTable, string.Format(CultureInfo.CurrentCulture, "The '{0}' table was not created.", tableName)); Assert.AreEqual(1, bypassTable.Columns.Count); // assert Versioning table does not have new entries DataTable versioningTable = GetTable(_options.VersioningTable); Assert.AreEqual(1, versioningTable.Rows.Count, "The versioning table has a wrong number of entries."); }
/// <summary> /// 欄位修改 /// </summary> /// <param name="rowSchema"></param> /// <returns></returns> public static string EditAreaColumn(DbSchema.Models.Schema rowSchema) { string DaoFieldName = Library.ConvertTitleCase(rowSchema.欄位名稱); string DaoFieldType = Library.DbDataTypeConvert(rowSchema.資料型別); int DbFieldLength = rowSchema.最大長度; string DisplayName = (rowSchema.自訂規則.ContainsKey("displayName")) ? rowSchema.自訂規則["displayName"] : DaoFieldName; if (DaoFieldName.ToLower() == "id" && IsIntegerType(DaoFieldType)) { //如果是 id 流水號,特別處理,不秀出來,然後是 int (就會是流水號) return string.Empty; } else { return EditAreaColumn(DisplayName, DaoFieldName, DaoFieldType, DbFieldLength); } }
protected override DbSchema GetSchema() { if (schema == null) { schema = new DbSchema("QFTimesRevisionDialog"); schema.Add("TimesRevisionID", typeof(int), "TimesRevisionID", false, true, true); schema.Add("Revision", typeof(int), "Revision", false); schema.Add("Component", typeof(int), "Component", true); schema.Add("IFU_value", typeof(decimal), "IFU_value", false); schema.Add("TimeKoef", typeof(decimal), "TimeKoef", false); schema.Add("Correction", typeof(int), "Correction", true); schema.Add("CorrectionNote", typeof(string), "CorrectionNote", true); schema.Add("PickType", typeof(int), "PickType", true); schema.Add("CheckPackage", typeof(bool), "CheckPackage", false); schema.Add("Created", typeof(DateTime), "Created", false); schema.Add("CreatedBy", typeof(string), "CreatedBy", false); schema.Add("Actual", typeof(bool), "Actual", false); schema.Add("MainComponent", typeof(int), "MainComponent", true); schema.Add("Note", typeof(string), "Note", true); schema.Add("TypeRevision", typeof(int), "TypeRevision", false); schema.Add("IFU", typeof(bool), "IFU", false); schema.Add("RevisionDone", typeof(bool), "RevisionDone", false); schema.Add("FileLink", typeof(string), "FileLink", true); schema.Add("MainCompRevision", typeof(int), "MainCompRevision", true); schema.Add("IFU_type", typeof(int), "IFU_type", true); schema.Add("CompCode", typeof(string), "CompCode", true); schema.Add("CompCategory", typeof(string), "CompCategory", true); schema.Add("CompStatus", typeof(string), "CompStatus", true); schema.Add("CompComent", typeof(string), "CompComent", true); schema.Add("CompPhotoDate", typeof(DateTime), "CompPhotoDate", true); schema.Add("CompTimesRevision", typeof(bool), "CompTimesRevision", true); schema.Add("TimeRevisionMainComp", typeof(bool), "TimeRevisionMainComp", true); schema.Add("TimeRevisionComp", typeof(bool), "TimeRevisionComp", true); } return schema; }
public void TestSelectingNonExistingProvider() { DbSchema schema = new DbSchema("...", new DbPlatform(Platform.SqlServer, 8)); Assert.IsNotNull(schema); // we should never hit this }
public SchemaRelation(DbSchema schema, SchemaTable parentTable, SchemaTable childTable, IEnumerable<SchemaColumn> childColumns, string relationName = null, bool isOneToOne = false, bool isRequired = true, bool isReversed = false) : this(schema, parentTable, childTable, parentTable.PrimaryKeys, childColumns, relationName, isOneToOne, isRequired, isReversed) { }