-
-
Save vkhorikov/849fae6f611fb12c3a4dad95db43cc4f to your computer and use it in GitHub Desktop.
NHibernate Async
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Customer customer = await session.GetAsync<Customer>(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Customer customer = await session.LoadAsync<Customer>(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Customer> customers = await session.Query<Customer>().ToListAsync(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Customer customer = await session | |
.Query<Customer>() | |
.Where(x => x.Name.Contains("Customer 1")) | |
.SingleOrDefaultAsync(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Customer customer = await session.CreateQuery("from Customer where Id = :Id") | |
.SetParameter("Id", 1) | |
.UniqueResultAsync<Customer>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task<Customer> task1 = session.GetAsync<Customer>(1); | |
Task<Customer> task2 = session.GetAsync<Customer>(2); | |
Customer[] customers = await Task.WhenAll(task1, task2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Customer customer1 = await session.GetAsync<Customer>(1); | |
Customer customer2 = await session.GetAsync<Customer>(2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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