问题描述
如何使用Detached crteria nhibernate进行以下查询
Hi,How to do below query using Detached crteria nhibernate
SELECT
(SELECT COUNT(id) FROM Employees WHERE YEAR(hire_date)=2011) as hirecnt,
(SELECT COUNT(id) FROM Employees WHERE YEAR(termination_date)=2011)as termcnt
我这样做但它不起作用...这里我用它来显示mvc图
string employmentstatus =终止;
DetachedCriteria criteria1 = DetachedCriteria.For< launchpad>()
.Add(Restrictions.Eq(Projectio) ns.SqlFunction(year,NHibernateUtil.Date,Projections.Property(Hire_Date)),2013))
.Add(Restrictiontions.Eq(Projections.SqlFunction(year,NHibernateUtil。 Date,Projections.Property(Termination_Date)),2011)&
(Restrictions.Eq(Employment_Status,Employmentstatus)))
.SetProjection(Projections.ProjectionList()
.Add(Projections.Alias(Projections.Count(Projections.Property(Hire_Date)),WnType ))
.Add(Projections.Alias(Projections.Count(Projections.Property(Termination_Date)),WnameType)))
.SetResultTransformer(new NHibernate.Transform.AliasToBeanResultTransformer(typeof(LaunchPad)));
返回FindAll(criteria1).ToList();
i am doing like this but its not working ...here i am using this for display mvc graph
string employmentstatus = "Terminated";
DetachedCriteria criteria1 = DetachedCriteria.For<launchpad>()
.Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.Date, Projections.Property("Hire_Date")), 2013))
.Add(Restrictions.Eq(Projections.SqlFunction("year", NHibernateUtil.Date, Projections.Property("Termination_Date")), 2011) &
(Restrictions.Eq("Employment_Status", employmentstatus)))
.SetProjection(Projections.ProjectionList()
.Add(Projections.Alias(Projections.Count(Projections.Property("Hire_Date")), "WnType"))
.Add(Projections.Alias(Projections.Count(Projections.Property("Termination_Date")), "WnameType")))
.SetResultTransformer(new NHibernate.Transform.AliasToBeanResultTransformer(typeof(LaunchPad)));
return FindAll(criteria1).ToList();
推荐答案
这篇关于分离的crteria nhibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!