A表对应的外键(B表)可以为null,所以数据是中外键的ID是null,条件查询就不会显示数据,但是我用
this.HibernateTemplate.LoadAll<T>();
ICriteria criteria = session.CreateCriteria(typeof(WareHouseArea), "wha");
//
criteria.CreateAlias("wha.WareHose", "h");
string areaCode = context.GetValue<string>("AreaCode");
string areaName = context.GetValue<string>("AreaName");
string remark = context.GetValue<string>("Remark");
long wareHouseId = context.GetValue<long>("WareHouseId");
if (!string.IsNullOrEmpty(areaCode))
{
criteria.Add(Expression.Like("wha.AreaCode", areaCode, MatchMode.Anywhere));
}
if (!string.IsNullOrEmpty(areaName))
{
criteria.Add(Expression.Like("wha.AreaName", areaName, MatchMode.Anywhere));
}
if (!string.IsNullOrEmpty(remark))
{
criteria.Add(Expression.Like("wha.Remark", remark, MatchMode.Anywhere));
}
if (wareHouseId!=0)
{
criteria.Add(Expression.Eq("h.Id", wareHouseId));
}
count = criteria.SetProjection(Projections.Count("Id").SetDistinct()).UniqueResult<int>();
if (count == 0)
{
return new List<WareHouseArea>();
}
你用了左连接