我尝试应用限制来查询NHibernate。代码已经存在。我没有编写项目的以下几行。
我的请求结果给出了批次列表。这些批次由状态不同的操作(“市场营销”,“已取消”,“暂停”)拥有。
限制条件应该只是批次有一个状态为“市场营销”的操作。
现在,无论操作的状态如何,所有项目都会返回。
感谢您的帮助
public static IList<ILot> GetLotByCriteria(IContact contact)
{
IList<ILot> list = new List<ILot>();
IList<ILot> finalList = new List<ILot>();
IList<int> listDept = new List<int>();
IDept dept;
if (contact.Departement != null)
{
dept = EntityFactory.GetRepository<IDept>().FindFirstByProperty("Numero", (int)contact.Departement);
if ((bool)contact.DeptAProximite) listDept = Dept.Rules.GetDeptLimitrophe((int)contact.Departement);
listDept.Add((int)contact.Departement);
}
IOperation operation = EntityFactory.GetById<IOperation>(contact.OperationId);
IRepository<ILot> repository = EntityFactory.GetRepository<ILot>();
Sage.Platform.Repository.IQueryable qry = (Sage.Platform.Repository.IQueryable)repository;
IExpressionFactory ef = qry.GetExpressionFactory();
Sage.Platform.Repository.ICriteria criteria = qry.CreateCriteria();
criteria.CreateAlias("Operation", "operation");
if (contact.NatureOperation != null) criteria.Add(ef.Eq("operation.NatureOperation", contact.NatureOperation));
if (contact.Pays != null) criteria.Add(ef.Eq("operation.Pays", contact.Pays));
if (contact.SurfaceTerrainMini != null) criteria.Add(ef.Ge("operation.Superficieterrain", contact.SurfaceTerrainMini));
if (contact.SurfaceTerrainMaxi != null) criteria.Add(ef.Le("operation.Superficieterrain", contact.SurfaceTerrainMaxi));
if (contact.BudgetMaxi != null) criteria.Add(ef.Le("PrixDefinitif", contact.BudgetMaxi));
if (operation != null) criteria.Add(ef.Eq("Operation", operation));
list = criteria.List<ILot>();
foreach (ILot item in list)
{
bool addToList = false;
if (listDept.Count > 0) addToList = IsDeptIn(listDept, item.Operation.Commune.CodePostal);
if (contact.NbPieces != null) addToList = IsNbPiecesIn(item.NbPieces, contact.NbPieces);
if (addToList) finalList.Add(item);
}
return finalList;
}