4

LINQプロバイダーでNHibernate2.1を使用していますが、このクエリから返される結果には複数のルートノードがあります。

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;
}

Criteria APIを使用すると、DistinctRootEntityResultTransformer()を呼び出して、一意のルートノードを確実に取得できることを知っていますが、ほとんどのクエリをNHibernate LINQプロバイダーに切り替えているところですが、同等。

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

4

1 に答える 1

2

NorthWindデータベースを使用して、テリトリーから個別のリージョンを取得したかったのですが...この構文は正しく機能しました。

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

ここに役立つかもしれないMicrosoftフォーラムの投稿があります。

于 2009-09-08T20:35:42.553 に答える