示例#1
0
 public static int CountQueryResult(QueryOver<Event> query)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         return query.GetExecutableQueryOver(session).Select(Projections.Count<Event>(e => e.EventId)).RowCount();
     }
 }
示例#2
0
        /// <summary>
        /// <paramref name="queryOver"/> 인스턴스를 <paramref name="session"/>에서 수행할 수 있는 <see cref="IQueryOver{T,T}"/> 를 생성합니다.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="session"></param>
        /// <param name="queryOver"></param>
        /// <returns></returns>
        public static IQueryOver <T, T> GetExecutableQueryOver <T>(this ISession session, QueryOver <T> queryOver)
        {
            session.ShouldNotBeNull("session");
            queryOver.ShouldNotBeNull("queryOver");

            var result = queryOver.GetExecutableQueryOver(session);

            return(result);
        }
示例#3
0
        /// <summary>
        /// The find one.
        /// </summary>
        /// <param name="queryOver">
        /// The query over.
        /// </param>
        /// <typeparam name="TReturn">
        /// Returned object type
        /// </typeparam>
        /// <returns>
        /// The <see cref="IFutureValue{TReturn}"/>.
        /// </returns>
        public IFutureValue <TReturn> FindOne <TReturn>(QueryOver <TEntity> queryOver)
        {
            if (Session == null)
            {
                throw new InvalidOperationException("Session is null");
            }

            return(queryOver.GetExecutableQueryOver(Session).FutureValue <TReturn>());
        }
示例#4
0
        public IEnumerable <Item> get_all_items_matching <Item>(Query <Item> query)
        {
            if (query == null)
            {
                throw new ArgumentNullException();
            }

            if (query is QueryImplByQueryOver <Item> )
            {
                QueryOver <Item> my_query = (query as QueryImplByQueryOver <Item>).Query;
                return(my_query.GetExecutableQueryOver(session).List());
            }
            throw new ArgumentException(
                      string.Format("Query {0} is not type supported.", query.GetType()));
        }
示例#5
0
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            MembershipUser   outp = null;
            QueryOver <User> q    = QueryOver
                                    .Of <User>()
                                    .Where(c => c.Username == username);
            User u = null;

            if (q != null)
            {
                u = q.GetExecutableQueryOver(currentSession).SingleOrDefault();
            }
            if (u != null)
            {
                outp = new WallMembershipUser(u.Username, u.Password);
            }
            return(outp);
        }
示例#6
0
        public IList <T> get_with_criteria <T>(QueryOver <T> detachedCriteria) where T : class
        {
            if (detachedCriteria == null)
            {
                Log.bound_to(this).log_a_warning_event_containing("Please ensure you send in a criteria when you want to limit records. Otherwise please consider using GetAll(). Returning empty list.");
                return(null);
            }

            IList <T> list;

            using (ensure_session_started())
            {
                IQueryOver <T, T> criteria = detachedCriteria.GetExecutableQueryOver(session);
                list = criteria.List <T>();
            }

            Log.bound_to(this).log_a_debug_event_containing("Repository found {0} records of type {1} with criteria {2}.", list.Count, typeof(T).Name, detachedCriteria.to_string());

            return(list);
        }
示例#7
0
		public void DetachedQuery_SimpleCriterion()
		{
			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				s.Save(new Person() { Name = "test person 1", Age = 20 });
				t.Commit();
			}

			using (ISession s = OpenSession())
			{
				QueryOver<Person> personQuery =
					new QueryOver<Person>()
						.Where(p => p.Name == "test person 1");

				IList<Person> actual =
					personQuery.GetExecutableQueryOver(s)
						.List();

				Assert.That(actual[0].Age, Is.EqualTo(20));
			}
		}
        public IQueryOver <T, T> QueryOver <T>(QueryOver <T> detachedQuery) where T : EntityBase
        {
            var query = detachedQuery.GetExecutableQueryOver(Session);

            return(query);
        }
示例#9
0
 /// <summary>
 /// The find one.
 /// </summary>
 /// <param name="queryOver">
 /// The query over.
 /// </param>
 /// <typeparam name="TReturn">
 /// Returned object type
 /// </typeparam>
 /// <returns>
 /// The <see cref="IFutureValue{TReturn}"/>.
 /// </returns>
 public IFutureValue <TReturn> FindOne <TReturn>(QueryOver <TEntity> queryOver)
 {
     return(queryOver.GetExecutableQueryOver(this.Manager.Session).FutureValue <TReturn>());
 }
示例#10
0
 /// <summary>
 /// The find all.
 /// </summary>
 /// <typeparam name="TOtherEntity">
 /// The other entity type
 /// </typeparam>
 /// <param name="queryOver">
 /// The query over.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{T}"/>.
 /// </returns>
 public IEnumerable <TOtherEntity> FindAll <TOtherEntity>(QueryOver <TEntity> queryOver)
 {
     return(queryOver.GetExecutableQueryOver(this.Manager.Session).Future <TOtherEntity>());
 }
示例#11
0
 public IQueryOver <T1, T1> ExecuteQuery <T1, T2>(QueryOver <T1, T2> query)
     where T1 : class
     where T2 : class
 {
     return(query.GetExecutableQueryOver(dbSession));
 }
示例#12
0
 public IQueryOver <T> ExecuteQuery <T>(QueryOver <T> query) where T : class
 {
     return(query.GetExecutableQueryOver(dbSession));
 }
示例#13
0
 public static IList<Event> GetQueryResult(int skip, int maxRow, QueryOver<Event> query)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         return query.GetExecutableQueryOver(session).Skip(skip).Take(maxRow).List();
     }
 }
示例#14
0
 /// <summary>
 /// The find all.
 /// </summary>
 /// <param name="queryOver">
 /// The query over.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{T}"/>.
 /// </returns>
 public IEnumerable <TEntity> FindAll(QueryOver <TEntity> queryOver)
 {
     return(queryOver.GetExecutableQueryOver(Session).Future <TEntity>());
 }