Create a gist now

Instantly share code, notes, and snippets.

@vkhorikov /1.cs
Last active Dec 5, 2017

Embed
What would you like to do?
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