/// <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 SessionWrapper session, ICollection <int> ids) where T : IInt32Id { if (!ids.Any()) { return(0); } string queryString; lock (GenerateStatementMutex) { var typeName = typeof(T); if (DeleteByIdCommands.ContainsKey(typeName)) { queryString = DeleteByIdCommands[typeName]; } else { queryString = string.Format("delete from {0} where {1} in (:{2})", typeName.Name.WrapObjectName(), nameof(IInt32Id.Id).WrapObjectName(), IdParameterName); DeleteByIdCommands[typeName] = queryString; } } var query = session.CreateQuery(queryString); int count = 0; for (var i = 0; i < ids.Count; i += DeleteBatchSize) { var batch = ids.Skip(i).Take(DeleteBatchSize).ToList(); count += query.SetParameterList(IdParameterName, batch).ExecuteUpdate(); } return(count); }
private void DeleteByKey <T>(string key, SessionWrapper session) where T : IExpirableWithKey { session.CreateQuery(SqlUtil.DeleteByKeyStatementDictionary[typeof(T)]) .SetParameter(SqlUtil.ValueParameterName, key) .ExecuteUpdate(); session.Flush(); }
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(); }
/// <summary> /// delete entities that implement IInt64Id, 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="id">Collection of ids to delete</param> /// <returns>the number of rows deleted</returns> public static long DeleteByInt32Id <T>(this SessionWrapper session, ICollection <int> id) where T : IInt32Id { if (!id.Any()) { return(0); } string queryString; lock (GenerateStatementMutex) { var typeName = typeof(T); if (DeleteByIdCommands.ContainsKey(typeName)) { queryString = DeleteByIdCommands[typeName]; } else { queryString = string.Format("delete from {0} where {1} in (:{2})", typeName.Name.WrapObjectName(), nameof(IInt32Id.Id).WrapObjectName(), IdParameterName); DeleteByIdCommands[typeName] = queryString; } } return(session.CreateQuery(queryString).SetParameterList(IdParameterName, id).ExecuteUpdate()); }