0

I am new in nHibernate and i want to convert following sql query in nHibernate criteria

SELECT DISTINCT fReportID, fFiscalYear FROM tFCMaster WHERE fPropertyID='100' 

I tried this:

Session.CreateCriteria<tFCMaster>().Add(Expression.Eq("fPropertyID", PropertyID)) .SetProjection(Projections.Distinct(Projections.Property("fFiscalYear"))) .List<tFCMaster>(); 

help will appreciated.

4
  • could you show is what you have tried, and why i didn't work Commented Oct 18, 2013 at 9:57
  • Session.CreateCriteria<tFCMaster>() .Add(Expression.Eq("fPropertyID", PropertyID)) .SetProjection(Projections.Distinct(Projections.Property("fFiscalYear"))) .List<tFCMaster>(); i tried this but it is giving error. Commented Oct 18, 2013 at 10:02
  • 1
    ok :) you should show that the error is by adding it to your question Commented Oct 18, 2013 at 10:41
  • if you want to map the result to tFcMaster, you have to include fPropertyID in your projection (assuming the table has exactly two columns) Commented Oct 18, 2013 at 12:17

1 Answer 1

1

Try this one.

criteria.SetProjection(Projections.Distinct(Projections.Property("Country")));

Best Regards.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.