示例#1
0
        private void SetExpireAt <T>(string key, DateTime?expire, StatelessSessionWrapper session) where T : IExpirableWithKey
        {
            var queryString = SqlUtil.SetExpireAtByKeyStatementDictionary[typeof(T)];

            session.CreateQuery(queryString)
            .SetParameter(SqlUtil.ValueParameterName, expire)
            .SetParameter(SqlUtil.IdParameterName, key)
            .ExecuteUpdate();
            //does nothing
        }
        /// <summary>
        ///     delete entities that implement IInt32Id, by using the value stored in their Id property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="session">Sessionwrapper instance to act upon</param>
        /// <param name="ids">Collection of ids to delete</param>
        /// <returns>the number of rows deleted</returns>
        public static long DeleteByInt32Id <T>(this StatelessSessionWrapper session, ICollection <int> ids) where T : IInt32Id
        {
            if (!ids.Any())
            {
                return(0);
            }

            var count = 0;

            for (var i = 0; i < ids.Count; i += DeleteBatchSize)
            {
                var batch = ids.Skip(i).Take(DeleteBatchSize).ToList();
                count += session.Query <T>().Where(j => batch.Contains(j.Id)).Delete();
            }

            return(count);
        }
        /// <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 StatelessSessionWrapper 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);
            }
        }
示例#4
0
 private void DeleteByKeyValue <T>(string key, string value, StatelessSessionWrapper session) where T : IKeyWithStringValue
 {
     session.Query <T>().Where(i => i.Key == key && i.Value == value).Delete();
     //does nothing
 }
示例#5
0
 private void DeleteByKey <T>(string key, StatelessSessionWrapper session) where T : IExpirableWithKey
 {
     session.Query <T>().Where(i => i.Key == key).Delete();
     //does nothing
 }