Concurrency

[Timestamp]
public byte[] RowVersion { get; set; }
modelBuilder.Entity<Department>()
    .Property(p => p.RowVersion).IsConcurrencyToken();

Transactions

using (var db = new MyDbContext(ConnectionString))
{
	using (var transaction = db.BeginTransaction(IsolationLevel.RepeatableRead))
	// Or: using (var transaction = db.Database.BeginTransaction())
	{
		try
		{
			// ...
			db.SaveChanges();
			transaction.Commit();
		}
		catch (Exception ex)
		{
			transaction.Rollback();
		}
	}
}
using (var conn = new SqlConnection("..."))
{
	conn.Open();
	using (var sqlTransaction = conn.BeginTransaction(IsolationLevel.Snapshot))
	{
		try
		{
			var sqlCommand = new SqlCommand();
			sqlCommand.Connection = conn;
			sqlCommand.Transaction = sqlTransaction;
			
			// ...

			using (var db = new MyDbContext(conn, contextOwnsConnection: false))
			{
				db.Database.UseTransaction(sqlTransaction);
				// ...
				db.SaveChanges();
			}

			sqlTransaction.Commit();
		}
		catch (Exception)
		{
			sqlTransaction.Rollback();
		}
	}
}

Connection Resiliency and Retry Logic