如何为不同数量创建查询
本文关键字:创建 查询 | 更新日期: 2023-09-27 18:26:07
我正在创建一个查询,根据收到的参数,该查询将有各种结果,如果满足某种情况,将为这种情况创建一个过滤器和一组结果。过滤器已经准备好了,但不知道如何在这些情况下设置数量。以下是查询:
public IEnumerable<ConeSlab> ConsultarPlacasAcompanhamento(String codigoLaminador, Int16 placasAEnfornar, Boolean placasEnfornadas, Int16 placasDesenfornadas, Boolean placasRejeitadas)
{
try
{
var criteria = DetachedCriteria.For<ConeSlab>()
.CreateAlias("Cone", "C")
.CreateAlias("Slab.SlabPDO", "SP")
.Add(Restrictions.Eq("C.Mill", codigoLaminador))
.Add(Restrictions.IsNotNull("C.IdentBeginDtm"))
.Add(Restrictions.IsNotNull("SP.IdentBeginDtm"));
var ordem = "SP.IdentBeginDtm";
Junction disjunction = Restrictions.Disjunction();
//Identificadas
if (placasAEnfornar > 0)
{
ICriterion criterion = Restrictions.Conjunction()
.Add(Restrictions.IsNotNull("SP.IdentEndDtm"))
.Add(Restrictions.IsNull("SP.ChargeDtm"))
.Add(Restrictions.IsNull("SP.RejectDtm"));
**//How to set here?**
disjunction.Add(criterion);
}
//Enfornadas
if (placasEnfornadas)
{
ICriterion criterion = Restrictions.Conjunction()
.Add(Restrictions.IsNotNull("SP.ChargeDtm"))
.Add(Restrictions.IsNull("SP.DischDtm"))
.Add(Restrictions.IsNull("SP.RejectDtm"));
disjunction.Add(criterion);
}
//Desenfornadas
if (placasDesenfornadas > 0)
{
ICriterion criterion = Restrictions.Conjunction()
.Add(Restrictions.IsNotNull("SP.DischDtm"))
.Add(Restrictions.IsNull("SP.MillDtm"))
.Add(Restrictions.IsNull("SP.RejectDtm"));
**//How to set here?**
disjunction.Add(criterion);
}
//Rejeitadas
if (placasRejeitadas)
criteria.Add(Restrictions.IsNull("SP.RejectDtm"));
criteria.Add(disjunction);
return coneSlabRepository.GetListCriteria(criteria, 300, Order.Desc(ordem));
}
catch (Exception ex)
{
Log.Error(AppStrings.EventNatureProgramacaoSequenciamento, LibStrings.MessageExceptionQuery, ex);
throw new LoggedException(ex.Message);
}
}
如何设置个人回报?
根据情况在Int中定义您的SetMaxResult,并在获取之前将其设置为Criteria。
int maxResults = 300; // Default value.
var criteria = DetachedCriteria.For<ConeSlab>()
.CreateAlias("Cone", "C")
.CreateAlias("Slab.SlabPDO", "SP")
.Add(Restrictions.Eq("C.Mill", codigoLaminador))
.Add(Restrictions.IsNotNull("C.IdentBeginDtm"))
.Add(Restrictions.IsNotNull("SP.IdentBeginDtm"));
Junction disjunction = Restrictions.Disjunction();
//Identificadas
if (placasAEnfornar > 0)
{
ICriterion criterion = Restrictions.Conjunction()
.Add(Restrictions.IsNotNull("SP.IdentEndDtm"))
.Add(Restrictions.IsNull("SP.ChargeDtm"))
.Add(Restrictions.IsNull("SP.RejectDtm"));
disjunction.Add(criterion);
maxResults = 10;
}
//Enfornadas
if (placasEnfornadas)
{
ICriterion criterion = Restrictions.Conjunction()
.Add(Restrictions.IsNotNull("SP.ChargeDtm"))
.Add(Restrictions.IsNull("SP.DischDtm"))
.Add(Restrictions.IsNull("SP.RejectDtm"));
disjunction.Add(criterion);
maxResults = 20;
}
//Desenfornadas
if (placasDesenfornadas > 0)
{
ICriterion criterion = Restrictions.Conjunction()
.Add(Restrictions.IsNotNull("SP.DischDtm"))
.Add(Restrictions.IsNull("SP.MillDtm"))
.Add(Restrictions.IsNull("SP.RejectDtm"));
disjunction.Add(criterion);
maxResults = 50;
}
criteria.Add(disjunction);
criteria.SetMaxResults(maxResults);