public static SetIdentityInsert ( ObjectName tableName, bool value ) : |
||
tableName | ObjectName | |
value | bool | |
return |
public static IDisposable DisableIdentity(ObjectName tableName) { SqlBuilder.SetIdentityInsert(tableName, true).ExecuteNonQuery(); return(new Disposable(() => { SqlBuilder.SetIdentityInsert(tableName, false).ExecuteNonQuery(); })); }
internal static SqlPreCommand CopyData(ITable newTable, DiffTable oldTable, Replacements rep) { var selectColumns = newTable.Columns .Select(col => oldTable.Columns.TryGetC(col.Key)?.Name ?? GetDefaultValue(newTable, col.Value, rep)) .ToString(", "); var insertSelect = new SqlPreCommandSimple( $@"INSERT INTO {newTable.Name} ({newTable.Columns.Values.ToString(a => a.Name, ", ")}) SELECT {selectColumns} FROM {oldTable.Name}"); if (!newTable.PrimaryKey.Identity) { return(insertSelect); } return(SqlPreCommand.Combine(Spacing.Simple, SqlBuilder.SetIdentityInsert(newTable.Name, true), insertSelect, SqlBuilder.SetIdentityInsert(newTable.Name, false) )); }
public static IDisposable DisableIdentity(Table table) { if (!table.IdentityBehaviour) { throw new InvalidOperationException("Identity is false already"); } table.IdentityBehaviour = false; if (table.PrimaryKey.Default == null) { SqlBuilder.SetIdentityInsert(table.Name, true).ExecuteNonQuery(); } return(new Disposable(() => { table.IdentityBehaviour = true; if (table.PrimaryKey.Default == null) { SqlBuilder.SetIdentityInsert(table.Name, false).ExecuteNonQuery(); } })); }