Это команда SQL:
Код: Выделить всё
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string sql = "UPDATE Customer SET CompanyName = @CompanyName, EmailAddress = @EmailAddress WHERE CustomerID = @CustomerID";
using (SqlCommand command = new SqlCommand(sql, connection))
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@CompanyName", customer.CompanyName);
command.Parameters.AddWithValue("@EmailAddress", customer.EmailAddress);
command.Parameters.AddWithValue("@CustomerID", customer.CustomerID);
command.ExecuteNonQuery();
}
}
Код: Выделить всё
public class DbLogUserIdInterceptor : DbConnectionInterceptor
{
public override InterceptionResult ConnectionOpening(
DbConnection connection,
ConnectionEventData eventData,
InterceptionResult result)
{
Debug.WriteLine("Connection is opening... insert UserID into session_context");
return base.ConnectionOpening(connection, eventData, result);
}
}
Код: Выделить всё
public class Database1DbContext : IdentityDbContext
{
public Database1DbContext(DbContextOptions options) : base(options)
{
}
public virtual DbSet Customer { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.AddInterceptors(new DbLogUserIdInterceptor());
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... nterceptor