NHhibernate OUTER JOIN
criteriaCount.CreateAlias(AdvertisementsProperties.City.ToString(), "city")
.CreateAlias(AdvertisementsProperties.Area.ToString(), "area")
.Add(Restrictions.Disjunction()
.Add(Expression.Like("Advertisement." + AdvertisementsProperties.Name.ToString(), text, MatchMode.Anywhere))
.Add(Expression.Like("Advertisement." + AdvertisementsProperties.Description.ToString(), text, MatchMode.Anywhere)))
/*.Add(Expression.Like("city." + CitiesProperties.Name, text, MatchMode.Anywhere))
.Add(Expression.Like("city." + CitiesProperties.SlovenianName, text, MatchMode.Anywhere))
.Add(Expression.Like("area." + AreasProperties.Name, text, MatchMode.Anywhere))
.Add(Expression.Like("area." + AreasProperties.SlovenianName, text, MatchMode.Anywhere))
.Add(Expression.Like("country." + CountriesProperties.Name, text, MatchMode.Anywhere))
.Add(Expression.Like("country." + CountriesProperties.SlovenianName, text, MatchMode.Anywhere)))*/
.List<Advertisements>();
CreateAlias or CreateCriteria create INNER JOIN in SQL. is it possible to create OUTER开发者_如何学Python JOIN because some of the relations can be null in my example and i do not need inner join all the time.
Look into CreateCriteria
method and NHibernate.SqlCommand.JoinType.LeftOuterJoin
parameter.
Your mappings can also determine this behavior, check out: http://ayende.com/Blog/archive/2009/04/13/nhibernate-mapping-ltsetgt.aspx
精彩评论