Привет
У меня один и тот же код и одни и те же hbms, работающие на двух разных машинах, каждая с nhibernate 3 (все находится в исходном хранилище, и последние версии проверяются оттуда), и nhibernate генерирует разные sql-запросы на каждой из машин
SearchResult<Contact> searchResult = new SearchResult<Contact>();
RepositoryLink<Contact> link = new RepositoryLink<Contact>();
ICriteria icriteria = null;
var clientCriteria = DetachedCriteria.For<Contact>("c")
.CreateCriteria("ContactRoles","cr", NHibernate.SqlCommand.JoinType.InnerJoin)
.CreateCriteria("AclRole", "ar" ,NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.Eq("ar.RoleName", RoleCode.Client));
foreach (var keyValuePair in searchCriteria)
{
switch (keyValuePair.Key)
{
case SearchClientCriterion.Branch:
clientCriteria.CreateCriteria("c.BuEntries", "be" , NHibernate.SqlCommand.JoinType.InnerJoin)
.CreateCriteria("be.BuLevel","bl", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.Eq("bl.LevelNo", keyValuePair.Value));
break;
case SearchClientCriterion.City:
clientCriteria.Add(Restrictions.Eq("c.City", keyValuePair.Value));
break;
case SearchClientCriterion.ClientID:
clientCriteria.Add(Restrictions.Eq("c.ID", keyValuePair.Value));
break;
case SearchClientCriterion.DOB:
break;
case SearchClientCriterion.FirstName:
clientCriteria.Add(Restrictions.Like("c.FirstName", keyValuePair.Value,MatchMode.Anywhere));
break;
case SearchClientCriterion.LastName:
clientCriteria.Add(Restrictions.Like("c.LastName", keyValuePair.Value, MatchMode.Anywhere));
break;
case SearchClientCriterion.State:
clientCriteria.Add(Restrictions.Eq("c.StateId", keyValuePair.Value));
break;
}
}
if(buLevel > 0)
clientCriteria.CreateCriteria("c.BuEntries", "be", NHibernate.SqlCommand.JoinType.InnerJoin)
.CreateCriteria("be.BuLevel", "bl", NHibernate.SqlCommand.JoinType.InnerJoin)
.Add(Restrictions.Eq("bl.LevelNo", buLevel));
var clientCountCriteria = (ICriteria)clientCriteria.GetExecutableCriteria(link.Session).Clone();
searchResult.Count = clientCountCriteria.SetProjection(Projections.CountDistinct("c.ID")).UniqueResult<int>();
icriteria = clientCriteria.GetExecutableCriteria(link.Session);
searchResult.Data = icriteria.SetFirstResult((pageIndex - 1) * pageSize).SetMaxResults(pageSize).List<Contact>();
это критерии
это генерирует:
SELECT count(distinct this_.contactkey) as y0_
FROM [Contact] this_
inner join [ContactRole] cr1_
on this_.contactkey = cr1_.contactkey
inner join [AclRole] ar2_
on cr1_.rolekey = ar2_.rolekey
WHERE ar2_.rolename = 'C' /* @p0 */
and this_.firstname like '%alex%' /* @p1 */
на одной машине и
SELECT count(distinct this_.contactkey) as y0_
FROM [Contact] this_
left outer join [ContactRole] contactrol1_
on this_.contactkey = contactrol1_.contactkey
left outer join [AclRole] aclrole2_
on contactrol1_.rolekey = aclrole2_.rolekey
WHERE this_.username like '%alex%' /* @p0 */
and not (aclrole2_.rolename = 'C' /* @p1 */)
Кто-нибудь знает, почему это так?