csharp 这个要点展示了如何使用NHibernate异步API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 这个要点展示了如何使用NHibernate异步API相关的知识,希望对你有一定的参考价值。

#region ICriteria async API

// Usage ICriteria.ListAsync<T>()
var customers = await session.CreateCriteria<Customer>().ListAsync<Customer>();

// Usage ICriteria.UniqueResultAsync<T>()
var customer = await session
	.CreateCriteria<Customer>()
	.Add(Restrictions.Eq("Name", "Erdtsieck"))
	.UniqueResultAsync<Customer>();

// Usage ICriteria.Future<T>() (returns IAwaitableEnumerable, that has a method AsTask())
var customers = session
	.CreateCriteria<Customer>()
	.Future<Customer>();
var products = session
	.CreateCriteria<Product>()
	.Future<Product>();

foreach (var customer in await customers.AsTask()) { } // async
foreach (var product in products) { } // sync (normal)

// Usage ICriteria.FutureValue<T>() (returns IFutureValue, that has a method ValueAsync())
var customerCountFuture = session
	.CreateCriteria<Customer>()
	.SetProjection(Projections.Count(Projections.Id()))
	.FutureValue<int>();
var productCountFuture = session
	.CreateCriteria<Product>()
	.SetProjection(Projections.Count(Projections.Id()))
	.FutureValue<int>();

var customerCount = await customerCountFuture.ValueAsync(); // async
var productCount = productCountFuture.Value; // sync (normal)

#endregion
#region IQueryOver async API

// Usage IQueryOver.ListAsync()
var person = await session.QueryOver<Customer>().ListAsync();

// Usage IQueryOver.ListAsync<T>()
var person = await session.QueryOver<Customer>().Select(p => p.Name).ListAsync<string>();
	
// Usage IQueryOver.SingleOrDefaultAsync<T>()
var customer = await session.QueryOver<Customer>().SingleOrDefaultAsync();

// Usage IQueryOver.Future<T>() (returns IAwaitableEnumerable, that has a method AsTask())
var customers = session.QueryOver<Product>().Future();
var products = session.QueryOver<Product>().Future();

foreach (var customer in await customers.AsTask()) { } // async
foreach (var product in products) { } // sync (normal)

// Usage IQueryOver.FutureValue<T>() (returns IFutureValue, that has a method ValueAsync())
var customerFuture = session.QueryOver<Customer>().FutureValue();
var productFuture = session.QueryOver<Product>().FutureValue();

var customer = await customerFuture.ValueAsync(); // async
var product = productFuture.Value; // sync (normal)

#endregion

以上是关于csharp 这个要点展示了如何使用NHibernate异步API的主要内容,如果未能解决你的问题,请参考以下文章

ruby 该要点向您展示了如何运行保留分析。我在博客上写了如何在此处运行保留分析:https://keen.io/blog/47823687779

ROS学习--RViz使用的要点

Android知识要点整理----Bitmap图片处理和展示

缓存的架构设计要点

使用 Python Qpid/Proton/Messenger(),如何过滤来自 Azure 事件中心的消息?

如何使用 Fluent-NHibernate 和 MySQL 指定自动递增 (int) 标识列