public static void DisableChangeTracking <T>(this DataConnection ctx) { ctx.CheckCtCompatible(); var descriptor = ctx.MappingSchema.GetEntityDescriptor(typeof(T)); ctx.Execute(Sql.TableDisableChangeTracking(descriptor.SchemaName, descriptor.TableName)); }
public static Task DisableChangeTrackingAsync <T>(this DataConnection ctx, CancellationToken token = default) { ctx.CheckCtCompatible(); var descriptor = ctx.MappingSchema.GetEntityDescriptor(typeof(T)); return(ctx.ExecuteAsync(Sql.TableDisableChangeTracking(descriptor.SchemaName, descriptor.TableName), token)); }
public static void EnsureChangeTrackingEnabled <T>(this DataConnection ctx, bool trackColumnUpdate = false) { ctx.CheckCtCompatible(); var descriptor = ctx.MappingSchema.GetEntityDescriptor(typeof(T)); if (descriptor.InheritanceMapping.Count > 0) { throw new ArgumentException($"Cannot change track entities with inheritance!"); } ctx.Execute(Sql.TableEnsureChangeTrackingEnabled(descriptor.SchemaName, descriptor.TableName, trackColumnUpdate)); }
/// <summary> /// read change tracking items for entity type /// </summary> /// <param name="ctx">connection</param> /// <param name="version">known last version</param> /// <param name="token">cancellation</param> /// <typeparam name="T">entity type</typeparam> /// <returns>enumerable of changes</returns> public static Task <IEnumerable <Changed <T> > > GetChangesAsync <T>(this DataConnection ctx, long version, bool onlyChanges = true, CancellationToken token = default) where T : class, new() { ctx.CheckCtCompatible(); var descriptor = ctx.MappingSchema.GetEntityDescriptor(typeof(T)); var(ctType, ex, map) = descriptor.GetCtTypeForEntity(); var method = _ctAsyncMethod.MakeGenericMethod(typeof(T), ctType); var query = (Task <IEnumerable <Changed <T> > >)method.Invoke(null, new object[] { ctx, ex, map, version, onlyChanges, token }); return(query); }
public static string GetDatabaseName(this DataConnection ctx) { ctx.CheckCtCompatible(); string connectionString; switch (ctx) { case var _ when ctx.Transaction != null: connectionString = ctx.Transaction.Connection.ConnectionString; break; case var _ when ctx.Connection != null: connectionString = ctx.Connection.ConnectionString; break; default: connectionString = ctx.ConnectionString; break; } return(new SqlConnectionStringBuilder(connectionString).InitialCatalog); }