public static int NextElfProefValue(ISession session, Guid counterId) { if (Config.Serializable != null) { using (var counterSession = Config.Default.CreateSession()) { var serializableCounter = new Counters(counterSession).CounterById[counterId]; var newValue = serializableCounter.Value + 1; serializableCounter.Value = newValue; counterSession.Commit(); return newValue; } } var counter = new Counters(session).CounterById[counterId]; counter.Value = counter.Value + 1; while (!IsValidElfProefNumber(counter.Value)) { counter.Value = counter.Value + 1; } return counter.Value; }