/// <getLimitProfilesOfUser> /// Get Limit Profiles Of User /// </summary> /// <param name="userid">User id.(Guid)</param> /// <param name="limit">Totale number required data. (int)</param> /// <returns>Return Array list with value.(ArrayList)</returns> public ArrayList getLimitProfilesOfUser(Guid userid, int limit) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Set defaulr max result int maxResult = 6; //Check the limit is not zero //if (limit == 0) // maxResult = 2; //Proceed action, to get records by user id. NHibernate.IQuery query = session.CreateQuery("from SocialProfile where UserId = :userid and ProfileType!='googleplus' and ProfileType!='googleanalytics' "); query.SetFirstResult(limit); query.SetMaxResults(maxResult); query.SetParameter("userid", userid); ArrayList alst = new ArrayList(); foreach (var item in query.Enumerable()) { alst.Add(item); } return(alst); } //End Transaction } //End Session }
private void OnQueryCreated(NHibernate.IQuery query) { if (EnablePage) { query.SetFirstResult(FirstResult); if (MaxResult != -1) { query.SetMaxResults(MaxResult); } } if (IsResultDistinct)// || m_hasCollection) { query.SetResultTransformer(new NHibernate.Transform.DistinctRootEntityResultTransformer()); } }
/// <getLimitProfilesOfUser> /// Get Limit Profiles Of User /// </summary> /// <param name="userid">User id.(Guid)</param> /// <param name="limit">Limit of Required Data. (int)</param> /// <param name="maxResult">Get Maximum results.(int)</param> /// <returns>Return Array list with value.(ArrayList)</returns> public ArrayList getLimitProfilesOfUser(Guid userid, int limit, int maxResult) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action to get user records. NHibernate.IQuery query = session.CreateQuery("from SocialProfile where UserId = :userid"); query.SetFirstResult(limit); query.SetMaxResults(maxResult); query.SetParameter("userid", userid); ArrayList alst = new ArrayList(); foreach (var item in query.Enumerable()) { alst.Add(item); } return(alst); } //End Transaction } //End Session }
public IList <Domain.Entitys.TBSysLogEntity> QuerySysLogsByPageInfo(int pageCode, int pageSize, int?logType, string ip, string startTime, string endTime, out long totalSize) { StringBuilder hqlBuilder = new StringBuilder(); hqlBuilder.Append(" select count(*) from TBSysLogEntity sl "); hqlBuilder.Append(" where 1=1 "); if (null != logType) { hqlBuilder.Append(" and sl.LogTypeId = ?"); } if (!string.IsNullOrEmpty(ip)) { hqlBuilder.Append(" and sl.LogIp like ?"); } if (!string.IsNullOrEmpty(startTime)) { hqlBuilder.Append(" and sl.LogDatetime >= " + "'" + startTime + "'"); } if (!string.IsNullOrEmpty(endTime)) { hqlBuilder.Append(" and sl.LogDatetime <= " + "'" + endTime + "'"); } NHibernate.IQuery query = this.Session.CreateQuery(hqlBuilder.ToString()); if (null != logType) { query.SetInt32(0, logType.Value); if (!string.IsNullOrEmpty(ip)) { query.SetString(1, "%" + ip + "%"); } } else { if (!string.IsNullOrEmpty(ip)) { query.SetString(0, "%" + ip + "%"); } } totalSize = query.UniqueResult <long>(); hqlBuilder = new StringBuilder(); hqlBuilder.Append(" select sl from TBSysLogEntity sl"); hqlBuilder.Append(" where 1=1 "); if (null != logType) { hqlBuilder.Append(" and sl.LogTypeId = ?"); } if (!string.IsNullOrEmpty(ip)) { hqlBuilder.Append(" and sl.LogIp like ?"); } if (!string.IsNullOrEmpty(startTime)) { hqlBuilder.Append(" and sl.LogDatetime >= " + "'" + startTime + "'"); } if (!string.IsNullOrEmpty(endTime)) { hqlBuilder.Append(" and sl.LogDatetime <= " + "'" + endTime + "'"); } hqlBuilder.Append(" order by sl.LogDatetime desc"); query = this.Session.CreateQuery(hqlBuilder.ToString()); if (null != logType) { query.SetInt32(0, logType.Value); if (!string.IsNullOrEmpty(ip)) { query.SetString(1, "%" + ip + "%"); } } else { if (!string.IsNullOrEmpty(ip)) { query.SetString(0, "%" + ip + "%"); } } query.SetFirstResult((pageCode - 1) * pageSize); query.SetMaxResults(pageSize); return(query.List <DASP.Domain.Entitys.TBSysLogEntity>()); }
/// <summary> /// 设置分页信息 /// </summary> /// <param name="query"></param> /// <param name="pagerInfo"></param> /// <returns></returns> public static NHibernate.IQuery SetPagerInfo(this NHibernate.IQuery query, Pager pagerInfo) { return(query.SetFirstResult(pagerInfo.PageSize * (pagerInfo.CurrentPageIndex - 1)) .SetMaxResults(pagerInfo.PageSize)); }