/// <summary> /// Delete entities that implement iexpirablewithid and have expired based on server's system date /// </summary> /// <typeparam name="T">The type of entity</typeparam> /// <param name="session">Sessionwrapper instance to act upon</param> /// <returns></returns> internal static long DeleteExpirableWithId <T>(this SessionWrapper session) where T : IExpirableWithId { var ids = session.Query <T>() .Where(i => i.ExpireAt < session.Storage.UtcNow) .Select(i => i.Id) .ToList(); return(session.DeleteByInt32Id <T>(ids)); }
public static void DoActionByExpression <T>(this SessionWrapper session, Expression <Func <T, bool> > expr, Action <T> action) where T : IExpirableWithId { var entities = session.Query <T>().Where(expr); foreach (var entity in entities) { action(entity); } }
/// <summary> /// Delete entities that implement iexpirablewithid and have expired based on server's system date /// </summary> /// <typeparam name="T">The type of entity</typeparam> /// <param name="session">Sessionwrapper instance to act upon</param> /// <param name="cutOffDate"></param> /// <returns></returns> internal static long DeleteExpirableWithId <T>(this SessionWrapper session, DateTime cutOffDate) where T : IExpirableWithId { var ids = session.Query <T>() .Where(i => i.ExpireAt < cutOffDate) .Select(i => i.Id) .ToList(); return(session.DeleteByInt32Id <T>(ids)); }
/// <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(); }