Jim*_*rts 29 nhibernate rowcount queryover
我正在使用作为NHibernate 3.x一部分的QueryOver api.我想得到一个行计数,但我正在使用的方法返回所有对象,然后获取集合的计数.有没有办法只返回行数的整数/长值?
我目前正在使用:
_session.QueryOver<MyObject>().Future().Count()
Run Code Online (Sandbox Code Playgroud)
Jim*_*rts 42
在使用api玩了一下后,这样做:
_session.QueryOver<MyObject>()
.Select(Projections.RowCount())
.FutureValue<int>()
.Value
Run Code Online (Sandbox Code Playgroud)
如果你不想将它作为未来归还,你可以SingleOrDefault<int>()改为.
Raf*_*ler 33
另一种方法
var count = Session.QueryOver<Employer>()
.Where(x => x.EmployerIsActive)
.RowCount();
Run Code Online (Sandbox Code Playgroud)
另一种方法:
int employerCount = session
.QueryOver<Employer>()
.Where(x => x.EmployerIsActive) // some condition if needed
.Select(Projections.Count<Employer>(x => x.EmployerId))
.SingleOrDefault<int>();
Run Code Online (Sandbox Code Playgroud)
小智 7
我这样使用:
public int QuantidadeTitulosEmAtraso(Sacado s)
{
TituloDesconto titulo = null;
Sacado sacado = null;
var titulos =
_session
.QueryOver<TituloDesconto>(() => titulo)
.JoinAlias(() => titulo.Sacado, () => sacado)
.Where(() => sacado.Id == s.Id)
.Where(() => titulo.Vencimento <= DateTime.Today)
.RowCount();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19357 次 |
| 最近记录: |