public IList <AcompanhamentoProducaoM2Consulta> ObterAcompanhamentoProducaoM2PorData(DateTime dataRecebimento, int tipoProcessoId) { return(this.Session.CreateCriteria(typeof(Processo)) .CreateAlias("Lote", "Lote") .CreateAlias("Lote.PacoteProcessado", "PP") .Add(Restrictions.Between("PP.ArquivoRecebidoEm", dataRecebimento.Date, dataRecebimento.Date.AddDays(1))) .Add(tipoProcessoId > 0 ? Restrictions.Eq("TipoDeProcesso.Id", tipoProcessoId) : Restrictions.IsNotNull("TipoDeProcesso")) .SetProjection(Projections.ProjectionList() .Add(Projections.Alias(Projections.GroupProperty("PP.Id"), "PacoteId")) .Add(Projections.Alias(Projections.GroupProperty("PP.Arquivo"), "NomeArquivo")) .Add(Projections.Alias(Projections.Max("PP.ArquivoRecebidoEm"), "DataRecepcao")) .Add(Projections.Alias(Projections.Max("PP.ArquivoImportadoEm"), "DataImportacao")) .Add(Projections.Alias(Projections.Max("Lote.DataFimIcr"), "DataOcr")) .Add(Projections.Alias(Projections.Max("Lote.DataFimIdentificacao"), "DataIdentificacao")) .Add(Projections.Alias(Projections.Max("Lote.DataFimDaMontagem"), "DataMontagem")) .Add(Projections.Alias(Projections.Max("Lote.DataFimDigitacao"), "DataDigitacao")) .Add(Projections.Alias(Projections.Max("Lote.DataFimValidacao"), "DataValidacao")) .Add(Projections.Alias(Projections.Max("Lote.DataFimProvaZero"), "DataProvaZero")) .Add(Projections.Alias(Projections.Max("Lote.DataFimFormalistica"), "DataFormalistica")) .Add(Projections.Alias(Projections.Max("Lote.DataAguardandoAprovacao"), "DataAprovacao")) .Add(Projections.Alias(Projections.Max("Lote.DataFimExportacao"), "DataExportacao")) .Add(Projections.Alias(Projections.Max("Lote.DataFinalizacao"), "DataFim"))) .SetResultTransformer(Transformers.AliasToBean(typeof(AcompanhamentoProducaoM2Consulta))) .AddOrder(Order.Asc("PacoteId")) .List <AcompanhamentoProducaoM2Consulta>()); }
public ICollection <Vacancy> SelectFilteredOrdered(VacancyFilter filter, VacancyOrdering ordering) { using (ISession session = NHibernateHelper.OpenSession()) { var criteria = session.CreateCriteria <Vacancy>(); Util.AddStringRestrictions(criteria, filter.TitleWords, "Title"); Util.AddStringRestrictions(criteria, filter.DescriptionWords, "Descriptions"); criteria.Add(Restrictions.Between ("Salary", filter.SalaryLowerBound, filter.SalaryUpperBound)); if (filter.Company != null) { criteria.Add(Restrictions .Where <Vacancy>(v => v.Employee.Company == filter.Company)); } if (!ordering.Salary) { criteria.AddOrder(Order.Desc("Salary")); } if (!ordering.Company) { criteria.AddOrder(Order.Desc("Company")); } return(criteria.List <Vacancy>()); } }
public void TestBuildNotBetweenExpressionCorrectly() { var between = Restrictions.Between("DateOfBirth", DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1)); var notBetween = Restrictions.Not(between); Assert.Equal("!(DateOfBirth >= @0 And DateOfBirth <= @1)", notBetween.GetExpressionBuilder().Build(commandBuilder)); }
private DetachedCriteria GetDetachedCriteria(bool cocheMandatory, int[] coches, short[] estados, bool excludeEstados, DateTime dateFrom, DateTime dateTo) { var dc = GetDetachedCriteria(cocheMandatory, coches, estados, excludeEstados) .Add(Restrictions.Between("Inicio", dateFrom, dateTo)); return(dc); }
/// <summary> /// Between (상하한을 포함하는 구간의 값을 구한다. 상하한에 대한 구간 검증은 하지 않는다!!!) /// </summary> /// <param name="propertyName">속성명</param> /// <param name="lo">하한</param> /// <param name="hi">상한</param> /// <returns></returns> public static ICriterion IsBetweenCriterion(this string propertyName, object lo, object hi) { propertyName.ShouldNotBeWhiteSpace("propertyName"); if (lo == null && hi == null) { throw new InvalidOperationException("Between 을 사용할 상하한 값 모두 null이면 안됩니다."); } if (IsDebugEnabled) { log.Debug("Between Criteria를 빌드합니다... propertyName=[{0}], lo=[{1}], hi=[{2}]", propertyName, lo, hi); } if (lo != null && hi != null) { return(Restrictions.Between(propertyName, lo, hi)); } // lo, hi 값 중 하나가 없다면 var result = Restrictions.Conjunction(); if (lo != null) { result.Add(Restrictions.Ge(propertyName, lo)); } if (hi != null) { result.Add(Restrictions.Le(propertyName, hi)); } return(result); }
public override AbstractCriterion GetExpression() { var exp = Restrictions.Conjunction().Add(Restrictions.Between("DataVencimento", DataInicialAbreviada(), DataFinalAbreviada())); switch (entrada.Value.ToString()) { case "Entrada": exp.Add(Restrictions.Eq("AReceber", true)); break; case "Saida": exp.Add(Restrictions.Eq("AReceber", false)); break; } switch (baixado.Value.ToString()) { case "Baixado": exp.Add(Restrictions.Eq("Baixado", true)); break; case "Aberto": exp.Add(Restrictions.Eq("Baixado", false)); break; } return(exp); }
public void DetachedRestrictions() { DetachedCriteria expected = DetachedCriteria.For <Person>("personAlias") .Add(Restrictions.Between("Age", 18, 65)) .Add(Restrictions.Between("personAlias.Age", 18, 65)) .Add(Restrictions.In("Name", new string[] { "name1", "name2", "name3" })) .Add(Restrictions.In("personAlias.Name", new ArrayList() { "name1", "name2", "name3" })); Person personAlias = null; QueryOver <Person> actual = QueryOver.Of <Person>(() => personAlias) .WhereRestrictionOn(p => p.Age).IsBetween(18).And(65) .WhereRestrictionOn(() => personAlias.Age).IsBetween(18).And(65) .AndRestrictionOn(p => p.Name).IsIn(new string[] { "name1", "name2", "name3" }) .AndRestrictionOn(() => personAlias.Name).IsIn(new ArrayList() { "name1", "name2", "name3" }); AssertCriteriaAreEqual(expected, actual); }
public void RestrictionsExtensions() { ICriteria expected = CreateTestCriteria(typeof(Person)) .Add(Restrictions.Like("Name", "%test%")) .Add(Restrictions.Like("Name", "test", MatchMode.End)) .Add(Restrictions.Like("Name", "test", MatchMode.Start, '?')) .Add(Restrictions.InsensitiveLike("Name", "%test%")) .Add(Restrictions.InsensitiveLike("Name", "test", MatchMode.Anywhere)) .Add(Restrictions.In("Name", new string[] { "name1", "name2" })) .Add(Restrictions.In("Name", new ArrayList() { "name3", "name4" })) .Add(Restrictions.Between("Age", 10, 20)); IQueryOver <Person> actual = CreateTestQueryOver <Person>() .Where(p => p.Name.IsLike("%test%")) .And(p => p.Name.IsLike("test", MatchMode.End)) .And(p => p.Name.IsLike("test", MatchMode.Start, '?')) .And(p => p.Name.IsInsensitiveLike("%test%")) .And(p => p.Name.IsInsensitiveLike("test", MatchMode.Anywhere)) .And(p => p.Name.IsIn(new string[] { "name1", "name2" })) .And(p => p.Name.IsIn(new ArrayList() { "name3", "name4" })) .And(p => p.Age.IsBetween(10).And(20)); AssertCriteriaAreEqual(expected, actual); }
//IList<NewsEntity.Models.CodeUmagf> IRepository<NewsEntity.Models.CodeUmagf>.GetAll() //{ // using (ISession session = NHibernateHelper.OpenSession()) // { // ICriteria criteria = session.CreateCriteria(typeof(NewsEntity.Models.CodeUmagf)); // criteria.AddOrder(Order.Desc("ID")); // criteria.AddOrder(Order.Asc("MI")); // return criteria.List<NewsEntity.Models.CodeUmagf>(); // } //} public IList <NewsEntity.Models.CodeUmagf> GetByPeriod(int station, int startYYYY, int startMM, int startDD, int endYYYY, int endMM, int endDD) { using (ISession session = NHibernateHelper.OpenSession()) { ICriteria criteria = session.CreateCriteria(typeof(NewsEntity.Models.CodeUmagf)); criteria.AddOrder(Order.Desc("ID")); criteria.Add(Restrictions.Eq("Station_ID", station)); System.DateTime startDate = new DateTime(startYYYY, startMM, startDD); System.DateTime endDate = new DateTime(endYYYY, endMM, endDD); var strYYYY = Projections.Cast(NHibernateUtil.String, Projections.Property("YYYY")); var strMM = Projections.Cast(NHibernateUtil.String, Projections.Property("MM")); var strDD = Projections.Cast(NHibernateUtil.String, Projections.Property("DD")); var sl = Projections.Cast(NHibernateUtil.String, Projections.Constant("/")); var projDate = Projections.SqlFunction("concat", NHibernateUtil.String, strDD, sl, strMM, sl, strYYYY); projDate = Projections.Cast(NHibernateUtil.DateTime, projDate); criteria.Add(Restrictions.Between(projDate, startDate, endDate)); criteria.AddOrder(Order.Asc("MI")); return(criteria.List <NewsEntity.Models.CodeUmagf>()); } }
public IList <T> GetByRange <T>(DateTime dateStart, DateTime dateEnd) where T : CalendarEvent { return(Session.CreateCriteria <T>().Add( Restrictions.Or(Restrictions.Between("Start", dateStart, dateEnd), Restrictions.Between("End", dateStart, dateEnd))) .List <T>()); }
public IList <Customer> Narrowing() { IList <Customer> customers = Session.CreateCriteria(typeof(Customer)).Add(Restrictions.Like("FirstName", "YJing%")) .Add(Restrictions.Between("LastName", "A%", "Y%")).List <Customer>(); return(customers); }
private static void GetCheckedInVisitors(DateTime fromDate, DateTime toDate) { using (var session = _sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var visitors = session.CreateCriteria <Visitor>() .Add(Restrictions.Between("DateCheckedIn", fromDate, toDate)) .SetProjection(Projections.ProjectionList() .Add(Projections.Property("DateCheckedIn"), "DateCheckedIn") .Add(Projections.Property("VisitorId"), "VisitorId") .Add(Projections.Property("VisitorName"), "VisitorName") .Add(Projections.Property("SecuritySystemBarCode"), "SecuritySystemBarCode")) .SetResultTransformer(Transformers.AliasToBean <Visitor>()) .List <Visitor>(); Console.WriteLine($"There are {visitors.Count} visitors checked in between {fromDate} and {toDate}\n"); foreach (var visitor in visitors) { Console.WriteLine( $"visitor.VisitorId: {visitor.VisitorId}\n" + $"visitor.VisitorName: {visitor.VisitorName}\n" + $"visitor.DateCheckedIn: {visitor.DateCheckedIn.ToString("yyyy-MM-dd")}\n" + $"visitor.SecuritySystemBarCode: {visitor.SecuritySystemBarCode}\n"); } Console.WriteLine(); tx.Commit(); } }
public ReadOnlyCollection <Transacao> AllByDate(DateTime dataInicial, DateTime dataFinal) { return(this.Session.QueryOver <Transacao>() .Where(Restrictions.Between("Data", dataInicial, dataFinal)) .List() .AsReadOnly()); }
/// <summary> /// Gets the transactions. /// </summary> /// <param name="filter"></param> /// <returns></returns> private IList <Transaction> GetTransactions(TransactionFilter filter) { if (filter == null) { throw new ArgumentNullException("filter"); } using (var session = SessionProvider.SessionFactory.OpenSession()) { //Build the criteria. ICriteria criteria = session.CreateCriteria <Transaction>(); if (filter.FromDate.HasValue && filter.ToDate.HasValue) { criteria.Add(Restrictions.Between("TransactionDate", filter.FromDate.Value, filter.ToDate.Value)); } if (filter.FromAmount.HasValue && filter.ToAmount.HasValue) { criteria.Add(Restrictions.Between("Amount", filter.FromAmount.Value, filter.ToAmount.Value)); } if (!string.IsNullOrEmpty(filter.Username)) { criteria.Add(Restrictions.Eq("CreatedBy", filter.Username)); } return(criteria.List <Transaction>()); } }
public CriteriaBuilder <T> BetweenAllowingNull(Expression <Func <T, object> > exp, object lower, object higher) { if (IsNotNull(lower) && IsNotNull(higher)) { this.detachedCriteria.Add(Restrictions.Between(expressionToStringWithAlias(exp), lower, higher)); } return(this); }
/// <summary> /// Apply a "between" constraint to the named property /// </summary> /// <param name="expression">lambda expression returning type's property</param> /// <param name="lo">low value of between</param> /// <param name="hi">high value of between</param> /// <returns>A NHibernate.Criterion.BetweenExpression.</returns> public static ICriterion Between(Expression <Func <object> > expression, object lo, object hi) { string property = ExpressionProcessor.FindMemberExpression(expression.Body); return(Restrictions.Between(property, lo, hi)); }
public IList <DbGameLottery> FetchAllRank5() { using (var pSession = SessionFactory.GameDatabase.OpenSession()) return(pSession .CreateCriteria <DbGameLottery>() .Add(Restrictions.Between("Rank", 5, 8)) .List <DbGameLottery>()); }
public void TestBuildBetweenExpressionCorrectly() { var criterion = Restrictions.Between("DateOfBirth", DateTime.Now.AddYears(-1), DateTime.Now.AddYears(1)); AssertExpression( $"{Sql.Column("DateOfBirth")} Between @{"0"} And @{"1"}", criterion.GetExpressionBuilder().Build(commandBuilder)); }
public IList <PacoteProcessado> ObterPorPeriodo(DateTime dataInicial, DateTime dataFinal) { var dataFinalFormatada = dataFinal.AddDays(1); return(this.Session.CreateCriteria(typeof(PacoteProcessado)) .Add(Restrictions.Between("ArquivoRecebidoEm", dataInicial, dataFinalFormatada)) .AddOrder(Order.Asc("ArquivoRecebidoEm")) .List <PacoteProcessado>()); }
public static List <Entities.Usuario> GetUsuarios(Entities.Usuario u) { try { using (ISession session = NHibernateHelper.OpenSession()) { //Option ICriteria crit = session.CreateCriteria(typeof(Entities.Usuario)); if (u.PkUsuario != 0 && u.PkUsuario.ToString() != "") { crit.Add(Restrictions.Like("PkUsuario", u.PkUsuario)); } if (!string.IsNullOrEmpty(u.Alias)) { crit.Add(Restrictions.Like("Alias", u.Alias)); } if (!string.IsNullOrEmpty(u.Clave)) { crit.Add(Restrictions.Like("Clave", u.Clave)); } if (u.Activo != null) { crit.Add(Restrictions.Eq("Activo", u.Activo)); } if (u.FchRegistro != null) { crit.Add(Restrictions.Between("FchRegistro", u.FchRegIni, u.FchRegFin)); } if (u.IdUsuarioReg != 0 && u.IdUsuarioReg.ToString() != "") { crit.Add(Restrictions.Like("IdUsuarioReg", u.IdUsuarioReg)); } if (u.FchActualizacion != null) { crit.Add(Restrictions.Between("FchActualizacion", u.FchActIni, u.FchActFin)); } if (u.IdUsuarioAct != 0 && u.IdUsuarioAct.ToString() != "") { crit.Add(Restrictions.Like("IdUsuarioAct", u.IdUsuarioAct)); } if (u.FchSession != null) { crit.Add(Restrictions.Like("FchSession", u.FchSession)); } if (!string.IsNullOrEmpty(u.TokenSession)) { crit.Add(Restrictions.Like("TokenSession", u.TokenSession)); } return((List <Entities.Usuario>)crit.List <Entities.Usuario>()); } } catch (Exception err) { return(new List <Entities.Usuario>()); } }
public void TestCreateBetweenCorrectly() { var propertyName = "Age"; var values = new object[] { 10, 20 }; ICriterion criterion = Restrictions.Between(propertyName, values[0], values[1]); AssertCriterion(criterion, propertyName, WhereOperator.Between, values); }
public static DayReportHc[] FindAllByDatetime(DateTime dtFrom, DateTime dtTo) { var criterion = new List <ICriterion> { Restrictions.Between("DateTime", dtFrom, dtTo) }; return((DayReportHc[])FindAll(typeof(DayReportHc), criterion.ToArray())); }
public MailCollection GetMailsByDate(DateTime initialDate, DateTime finalDate, ISession session) { IList <MailEntity> databaseMails = session.CreateCriteria <MailEntity>() .Add(Restrictions.Eq("MailAccountEntity", this.Entity)) .Add(Restrictions.Between("Date", initialDate, finalDate)) .List <MailEntity>(); return(new MailCollection(databaseMails)); }
public void SqlOperators() { ICriteria expected = CreateTestCriteria(typeof(Person), "personAlias") .Add(Restrictions.Between("Age", 18, 65)) .Add(Restrictions.Between("personAlias.Age", 18, 65)) .Add(Restrictions.Not(Restrictions.Between("personAlias.Age", 10, 20))) .Add(!Restrictions.In("Name", new string[] { "name4" })) .Add(Restrictions.In("Name", new string[] { "name1", "name2", "name3" })) .Add(Restrictions.In("Name", new ArrayList() { "name1", "name2", "name3" })) .Add(Restrictions.InG <int>("Age", new int[] { 1, 2, 3 })) .Add(Restrictions.InsensitiveLike("Name", "test")) .Add(Restrictions.InsensitiveLike("Name", "tEsT", MatchMode.Anywhere)) .Add(Restrictions.IsEmpty("Children")) .Add(Restrictions.Not(Restrictions.IsEmpty("Children"))) .Add(Restrictions.IsNotEmpty("Children")) .Add(Restrictions.IsNotNull("Name")) .Add(Restrictions.IsNull("Name")) .Add(Restrictions.Like("Name", "%test%")) .Add(Restrictions.Like("Name", "test", MatchMode.Anywhere)) .Add(Restrictions.Like("Name", "test", MatchMode.Anywhere, '?')) .Add(Restrictions.NaturalId() .Set("Name", "my name") .Set("personAlias.Age", 18)); Person personAlias = null; var actual = CreateTestQueryOver <Person>(() => personAlias) .Where(Restrictions.On <Person>(p => p.Age).IsBetween(18).And(65)) .And(Restrictions.On(() => personAlias.Age).IsBetween(18).And(65)) .And(Restrictions.On(() => personAlias.Age).Not.IsBetween(10).And(20)) .And(!Restrictions.On <Person>(p => p.Name).IsIn(new string[] { "name4" })) .And(Restrictions.On <Person>(p => p.Name).IsIn(new string[] { "name1", "name2", "name3" })) .And(Restrictions.On <Person>(p => p.Name).IsIn(new ArrayList() { "name1", "name2", "name3" })) .And(Restrictions.On <Person>(p => p.Age).IsInG <int>(new int[] { 1, 2, 3 })) .And(Restrictions.On <Person>(p => p.Name).IsInsensitiveLike("test")) .And(Restrictions.On <Person>(p => p.Name).IsInsensitiveLike("tEsT", MatchMode.Anywhere)) .And(Restrictions.On <Person>(p => p.Children).IsEmpty) .And(Restrictions.On <Person>(p => p.Children).Not.IsEmpty) .And(Restrictions.On <Person>(p => p.Children).IsNotEmpty) .And(Restrictions.On <Person>(p => p.Name).IsNotNull) .And(Restrictions.On <Person>(p => p.Name).IsNull) .And(Restrictions.On <Person>(p => p.Name).IsLike("%test%")) .And(Restrictions.On <Person>(p => p.Name).IsLike("test", MatchMode.Anywhere)) .And(Restrictions.On <Person>(p => p.Name).IsLike("test", MatchMode.Anywhere, '?')) .And(Restrictions.NaturalId() .Set <Person>(p => p.Name).Is("my name") .Set(() => personAlias.Age).Is(18)); AssertCriteriaAreEqual(expected, actual); }
public AbstractCriterion And(object hi) { if (isNot) { return(Restrictions.Not(Restrictions.Between(propertyName, lo, hi))); } return(Restrictions.Between(propertyName, lo, hi)); }
/// <summary> /// Builds the criterion. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <returns></returns> protected override ICriterion BuildCriterion(string fieldName) { ICriterion result = Restrictions.Between(fieldName, LoValue, HiValue); if (Negation) { result = Restrictions.Not(result); } return(result); }
public IList <MeteologyEntity.Models.Groza.Groza> GetByPeriod(DateTime dateBgn, DateTime dateEnd) { using (ISession session = NHibernateHelper.OpenSession()) { ICriteria criteria = session.CreateCriteria(typeof(MeteologyEntity.Models.Groza.Groza)); criteria.Add(Restrictions.Between("fixed_at", dateBgn, dateEnd)); criteria.AddOrder(Order.Desc("ID")); return(criteria.List <MeteologyEntity.Models.Groza.Groza>()); } }
public static GasConcentrationProbeData[] FindHistaryData(string probeId, DateTime startTime, DateTime endTime) { var criterion = new List <ICriterion> { Restrictions.Eq("Probe.ProbeId", probeId), Restrictions.Between("RecordTime", startTime, endTime) }; return(FindAll(criterion.ToArray())); }
public JsResultObject createNewOrder(OrderModel order) { JsResultObject re = new JsResultObject(); this.OpenSession(); ICriteria icr = this.session.CreateCriteria <OrderModel>(); DateTime startDate = new DateTime(order.createDate.Year, order.createDate.Month, order.createDate.Day, 0, 0, 0); DateTime endDate = startDate.AddDays(1); icr.Add(Restrictions.And( Restrictions.And( Restrictions.Eq("hotelId", order.hotelId) , Restrictions.Between("createDate", startDate, endDate) ), Restrictions.Eq("guestsNameArray", order.guestsNameArray) )); IList <OrderModel> orders = icr.List <OrderModel>(); if (orders.Count > 0) { re.code = JsResultObject.CODE_ERROR; re.msg = "同名住客不能在同一天预订同一间酒店的房间"; return(re); } string[] guestsName = order.guestsNameArray.Split(','); if (string.IsNullOrEmpty(order.guestsNameArray)) { re.code = JsResultObject.CODE_ERROR; re.msg = "必须至少填写一个住客的名字"; return(re); } Array.Sort(guestsName); order.guestsNameArray = ObjectUtil.ToUnionString(guestsName, ','); re = ServiceUtil.ValidateMoblie(order.mobile); if (re.code != JsResultObject.CODE_SUCCESS) { return(re); } // re = ServiceUtil.ValidateEmail(order.email); // if (re.code != JsResultObject.CODE_SUCCESS) { return re; } re = BaseZdBiz.Save(order); ConfigModel config = AdminBiz.GetCurrConfig(); if (config.autoOrderInd == BaseModel.IND_Y) { re = submitOrder(order, true); } return(re); }
public static DayReportHc[] SlicedFindByDatetime(int firstResult, int maxResult, DateTime startTime, DateTime endTime) { var criterion = new ICriterion[] { Restrictions.Between("Datetime", startTime, endTime) }; var results = (DayReportHc[])SlicedFindAll(typeof(DayReportHc), firstResult, maxResult, criterion); return(results); }