/// <summary> /// Checks if the recycled ID already exists in the database. /// </summary> /// <param name="lowerId">the ID to check for</param> /// <param name="type">the entity ID type to check for</param> /// <returns>true if the ID has already been recycled; false if not</returns> public static bool DoesIdExist(uint lowerId, EntityIdType type) { using (var db = RealmServerDataContext.GetContext()) { return(RecycledIdByLowerAndType(db, (int)lowerId, (int)type).Count() > 0); } }
/// <summary> /// Adds a new recycled ID to the database. /// </summary> /// <param name="id">the ID to add</param> public static void AddRecycledId(RecycledEntityId id) { using (var db = RealmServerDataContext.GetContext()) { db.RecycledEntityIds.InsertOnSubmit(id); db.SubmitChanges(); } }
/// <summary> /// Removes a recycled ID from the database. /// </summary> /// <param name="id">the ID to remove</param> public static void RemoveRecycledId(RecycledEntityId id) { using (var db = RealmServerDataContext.GetContext()) { db.RecycledEntityIds.Attach(id); db.RecycledEntityIds.DeleteOnSubmit(id); db.SubmitChanges(); } }
/// <summary> /// Gets the first available ID of the given type. /// </summary> /// <param name="type">the type of entity ID to get</param> /// <returns>a <see cref="RecycledEntityId" /> object representing the ID; null if no ID was available</returns> public static RecycledEntityId GetFirstRecycledId(EntityIdType type) { using (var db = RealmServerDataContext.GetContext()) { IQueryable <RecycledEntityId> ids = RecycledIdsByType(db, (int)type); return(ids.FirstOrDefault()); } }