Skip to content

Instantly share code, notes, and snippets.

@vkhorikov
Last active January 8, 2022 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vkhorikov/849fae6f611fb12c3a4dad95db43cc4f to your computer and use it in GitHub Desktop.
Save vkhorikov/849fae6f611fb12c3a4dad95db43cc4f to your computer and use it in GitHub Desktop.
NHibernate Async
Customer customer = await session.GetAsync<Customer>(1);
Customer customer = await session.LoadAsync<Customer>(1);
List<Customer> customers = await session.Query<Customer>().ToListAsync();
Customer customer = await session
.Query<Customer>()
.Where(x => x.Name.Contains("Customer 1"))
.SingleOrDefaultAsync();
Customer customer = await session.CreateQuery("from Customer where Id = :Id")
.SetParameter("Id", 1)
.UniqueResultAsync<Customer>();
Task<Customer> task1 = session.GetAsync<Customer>(1);
Task<Customer> task2 = session.GetAsync<Customer>(2);
Customer[] customers = await Task.WhenAll(task1, task2);
Customer customer1 = await session.GetAsync<Customer>(1);
Customer customer2 = await session.GetAsync<Customer>(2);
using (ISession session = sessionFactory.OpenSession())
using (ITransaction transaction = session.BeginTransaction())
{
Customer customer = await session.GetAsync<Customer>(1);
customer.Name = "Customer 3";
await session.SaveOrUpdateAsync(customer);
await transaction.CommitAsync();
}
List<Order> orders = await customer.Orders
.AsQueryable()
.Where(x => x.Amount > 10)
.ToListAsync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment