Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,How to do below query using Detached crteria nhibernate



SQL
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



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();
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900