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或CreateCriteria在SQL中创建INNER JOIN。是否可以创建OUTER JOIN,因为在我的示例中,某些关系可以为null,而且我不需要一直使用内连接。
答案 0 :(得分:4)
查看CreateCriteria
方法和NHibernate.SqlCommand.JoinType.LeftOuterJoin
参数。
您的映射也可以确定此行为,请查看:http://ayende.com/Blog/archive/2009/04/13/nhibernate-mapping-ltsetgt.aspx