For now i solve this by

            var subCriteria = DetachedCriteria.For<Company>("companyDT")
                .CreateCriteria("Translations")
                .Add(!Restrictions.Eq("Locale", locale))
                
.SetProjection(Projections.Distinct(Property.ForName("companyDT.CompanyId")));
 
             query.CreateCriteria("Translations", "translations")
                               .Add(Expression.Disjunction()
                                              .Add(Restrictions.Eq("Locale", 
locale)) // We select all elements from needed locale, and other elements that 
not selected yet.
                                              
.Add(Property.ForName("company.CompanyId").In(subCriteria)))
                               .AddOrder(new 
Order(Projections.SqlProjection(string.Format("case when {{alias}}.Locale = 
'{0}' then 1 else 0 end as order", locale), new[] { "order" }, 
                                   new[] { NHibernateUtil.String }), false))


четверг, 21 февраля 2013 г., 9:27:54 UTC+2 пользователь Vladislav написал:
>
> I have problem with selecting objects from database with one-to-many 
> relations.     
> Database scheme is like this : 
> Company                         CompanyTranslations
> ________                         _________________
> CompanyId                       ID
> ....                                   CompanyId 
>                                        CompanyName
>                                        Locale
>
>  When I create criteria I use Create alias with LeftOuterJoin and 
> additional join parameter for locale  
>
>  var query = var query = Session.CreateCriteria<Company>("company")
>                 .Add(Restrictions.Eq("IsActive", true));
>             query.CreateAlias("Translations", "translationsF", 
> JoinType.LeftOuterJoin, Restrictions.Eq("Locale", "en").IgnoreCase());
>
>
> After that I have detached criteria for order by table fields like 
> CompanyName and pagination. 
>
> Selection works correct but after that when I want to get translation from 
> property they contain empty or on element which locale matches with alias 
> restriction. 
>
> In mapping for Translation property I tried to use 
> HasMany<CompanyTranslation>(Reveal.Member<Company>("Translations")).KeyColumn("CompanyId").Cascade.All().Fetch.Subselect()/Join();
>
> But it doesn't get any results. 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to