コード例 #1
0
 private void DeleteByKey <T>(string key, SessionWrapper session) where T : IExpirableWithKey
 {
     session.CreateQuery(SqlUtil.DeleteByKeyStatementDictionary[typeof(T)])
     .SetParameter(SqlUtil.ValueParameterName, key)
     .ExecuteUpdate();
     session.Flush();
 }
コード例 #2
0
        private void SetExpireAt <T>(string key, DateTime?expire, SessionWrapper session) where T : IExpirableWithKey
        {
            var queryString = SqlUtil.SetExpireAtByKeyStatementDictionary[typeof(T)];

            session.CreateQuery(queryString)
            .SetParameter(SqlUtil.ValueParameterName, expire)
            .SetParameter(SqlUtil.IdParameterName, key)
            .ExecuteUpdate();
            session.Flush();
        }
コード例 #3
0
        /// <summary>
        /// do an upsert into a table
        /// </summary>
        /// <typeparam name="T">The entity type to upsert</typeparam>
        /// <param name="session">a SessionWrapper instance to act upon</param>
        /// <param name="matchFunc">A function that returns a single instance of T</param>
        /// <param name="changeAction">A delegate that changes specified properties of instance of T </param>
        /// <param name="keysetAction">A delegate that sets the primary key properties of instance of T if we have to do an upsert</param>
        public static void UpsertEntity <T>(this SessionWrapper session, Expression <Func <T, bool> > matchFunc,
                                            Action <T> changeAction,
                                            Action <T> keysetAction) where T : new()
        {
            var entity = session.Query <T>().SingleOrDefault(matchFunc);

            if (entity == null)
            {
                entity = new T();
                keysetAction(entity);
                changeAction(entity);
                session.Insert(entity);
            }
            else
            {
                changeAction(entity);
                session.Update(entity);
            }
            session.Flush();
        }