views:

35

answers:

0

I want to execute follow command in ActiveRecord.

select distinct(Name) from DbTemplateNw;

I tried this code but it's alway return all record in table (there are many duplicate name).

public static DbTemplateNw[] GetDistintTemplate()
{
    DetachedCriteria distinctCriteria = DetachedCriteria.For(typeof(DbTemplateNw))
        .SetProjection(Projections.Distinct(Property.ForName("Name")));

    DetachedCriteria fullCriteria = DetachedCriteria.For(typeof(DbTemplateNw))
        .Add(Subqueries.PropertyIn("Name", distinctCriteria));

    DbTemplateNw[] result = ActiveRecordBase<DbTemplateNw>.FindAll(fullCriteria, new Order[] { new Order("Name", true) });

    return result;
}

How to solve this problem.
I don't worry if result contain only string (only name not full object).

Thank you very much.

related questions