views:

382

answers:

1

I'm using NHibernate 2.1 with the LINQ provider and the results I get back from this query have multiple root nodes:

public IList<Country> GetAllCountries()
{
  List<Country> results = (from country in _session.Linq<Country>()
                           from states in country.StateProvinces
                           orderby country.DisplayOrder, states.Description 
                           select country)
                           .Distinct()
                           .ToList();

            return results;
}

I know that using the Criteria API you can call DistinctRootEntityResultTransformer() to ensure that you get a unique root node, but I'm in the process of switching most of my queries over to the NHibernate LINQ provider, and I don't see an equavalient.

http://nhforge.org/wikis/howtonh/get-unique-results-from-joined-queries.aspx

+2  A: 

Using the NorthWind database, I wanted to get back the distinct regions from the territories... This syntax worked correctly.

(from t in Territories
from r in Regions
select  new
{
    r.RegionDescription
})
.Distinct().OrderBy(r => r.RegionDescription)

There is a post on a Microsoft forum here that may help.

RSolberg