Exemple #1
0
 public IEnumerator <T> GetEnumerator()
 {
     foreach (T record in DataMapper.Select(SessionFactory.GetCurrentSession(typeof(T)), this))
     {
         yield return(record);
     }
 }
Exemple #2
0
        /// <summary>
        /// Gets an instance of an active NHibernate transaction.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static Transaction GetTransaction(string key)
        {
            string      transKey    = String.Format("TRANS_{0}", key);
            Transaction transaction = SessionStorage.GetCurrent <Transaction>(transKey);

            if (transaction != null && transaction.IsActive)
            {
                return(new Transaction());
            }

            transaction = new Transaction(SessionFactory.GetCurrentSession(key).Connection);
            SessionStorage.SetCurrent(transKey, transaction);

            return(transaction);
        }
Exemple #3
0
 /// <summary>
 /// Gets an entity from a partitioned table in the db by its ID and partition key timestamp.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="timestamp"></param>
 /// <returns></returns>
 public virtual ENTITY Get(object id, object partitionKey)
 {
     return(DataMapper.Get <ENTITY>(SessionFactory.GetCurrentSession(SessionKey), id, partitionKey));
 }
Exemple #4
0
 /// <summary>
 /// Stronly typed method to get an entity by Id. This will load the entity from the database.
 /// </summary>
 /// <typeparam name="ENTITY"></typeparam>
 /// <param name="id"></param>
 /// <returns></returns>
 public virtual ENTITY Get(object id, bool forUpdate = false)
 {
     return(DataMapper.Get <ENTITY>(SessionFactory.GetCurrentSession(SessionKey), id, forUpdate));
 }
Exemple #5
0
 /// <summary>
 /// Run an ad-hoc query.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="sql"></param>
 /// <param name="parameters"></param>
 public static List <Dictionary <string, object> > CustomQuery(string key, string sql, Dictionary <string, object> parameters)
 {
     return(CustomQuery(SessionFactory.GetCurrentSession(key), sql, parameters));
 }
Exemple #6
0
 public virtual int Count()
 {
     this.SelectStr = String.Format("SELECT COUNT(*) FROM {0}", DataMapper.EscapeName(Mapping.TableName));
     return(Convert.ToInt32(DataMapper.SelectScalar(SessionFactory.GetCurrentSession(typeof(T)), this)));
 }
Exemple #7
0
 public virtual int ExecuteNonQuery()
 {
     return(DataMapper.NonQuery(SessionFactory.GetCurrentSession(typeof(T)), this));
 }