Beispiel #1
0
        public WorkingWithDocumentIdentifiers(string g)
        {
            var store   = new DocumentStore();
            var session = store.OpenSession();

            #region commands_identity_generate

            var command = new NextIdentityForCommand("products");
            session.Advanced.RequestExecutor.Execute(command, session.Advanced.Context);
            var identity = command.Result;

            var doc = new DynamicJsonValue
            {
                ["Name"] = "My RavenDB"
            };

            var blittableDoc = session.Advanced.EntityToBlittable.ConvertEntityToBlittable(doc, null);

            var putCommand = new PutDocumentCommand("products/" + identity, null, blittableDoc);

            session.Advanced.RequestExecutor.Execute(putCommand, session.Advanced.Context);

            #endregion

            #region commands_identity_set

            var seedIdentityCommand = new SeedIdentityForCommand("products", 1994);

            #endregion
        }
Beispiel #2
0
        private long GetNextIdForUser()
        {
            var getIdsCommand = new NextIdentityForCommand(Conventions.CollectionNameFor <TUser>(docStore));

            using var dbSession = docStore.OpenSession();
            dbSession.Advanced.RequestExecutor.Execute(getIdsCommand, dbSession.Advanced.Context);
            return(getIdsCommand.Result);
        }
Beispiel #3
0
 public long GetNextNumericalKey(string collectionName)
 {
     using (var shortTermSingleUse = JsonOperationContext.ShortTermSingleUse())
     {
         var command = new NextIdentityForCommand(collectionName);
         _documentStore.GetRequestExecutor("Master").Execute(command, shortTermSingleUse);
         return(command.Result);
     }
 }
        public async Task NextIdentityFor()
        {
            using (var store = GetDocumentStore())
            {
                using (var s = store.OpenSession())
                {
                    var entity = new User
                    {
                        LastName = "Adi"
                    };

                    s.Store(entity, "users|");
                    s.SaveChanges();
                }

                using (var commands = store.Commands())
                {
                    var command = new NextIdentityForCommand("users");

                    await commands.RequestExecutor.ExecuteAsync(command, commands.Context);
                }

                using (var s = store.OpenSession())
                {
                    var entity = new User
                    {
                        LastName = "Avivi"
                    };

                    s.Store(entity, "users|");
                    s.SaveChanges();
                }

                using (var s = store.OpenSession())
                {
                    var entityWithId1 = s.Load <User>("users/1");
                    var entityWithId2 = s.Load <User>("users/2");
                    var entityWithId3 = s.Load <User>("users/3");
                    var entityWithId4 = s.Load <User>("users/4");

                    Assert.NotNull(entityWithId1);
                    Assert.NotNull(entityWithId3);
                    Assert.Null(entityWithId2);
                    Assert.Null(entityWithId4);

                    Assert.Equal("Adi", entityWithId1.LastName);
                    Assert.Equal("Avivi", entityWithId3.LastName);
                }
            }
        }