public void DeleteEntity()
        {
            string projectId   = _fixture.ProjectId;
            string namespaceId = _fixture.NamespaceId;

            // Copied from InsertEntity; we want to create a new one to delete.
            KeyFactory keyFactory = new KeyFactory(projectId, namespaceId, "Task");
            Entity     entity     = new Entity
            {
                Key                  = keyFactory.CreateIncompleteKey(),
                ["category"]         = "Personal",
                ["done"]             = false,
                ["priority"]         = 4,
                ["description"]      = "Learn Cloud Datastore",
                ["percent_complete"] = 75.0
            };
            DatastoreClient insertClient = DatastoreClient.Create();
            CommitResponse  response     = insertClient.Commit(projectId, Mode.NonTransactional, new[] { entity.ToInsert() });
            Key             key          = response.MutationResults[0].Key;

            // Sample: DeleteEntity
            DatastoreClient client = DatastoreClient.Create();
            // If you have an entity instead of just a key, then entity.ToDelete() would work too.
            CommitResponse commit = insertClient.Commit(projectId, Mode.NonTransactional, new[] { key.ToDelete() });
            // End sample
        }
示例#2
0
        /// <inheritdoc />
        public override CommitResponse Commit(CallSettings callSettings = null)
        {
            // TODO: What if there are no mutations? Just rollback?
            CheckActive();
            var response = _client.Commit(_projectId, Mode.Transactional, TransactionId, _mutations);

            _active = false;
            return(response);
        }
示例#3
0
        public void Commit2()
        {
            // Snippet: Commit(string,CommitRequest.Types.Mode,IEnumerable<Mutation>,CallSettings)
            // Create client
            DatastoreClient datastoreClient = DatastoreClient.Create();
            // Initialize request argument(s)
            string projectId = "";

            CommitRequest.Types.Mode mode      = CommitRequest.Types.Mode.Unspecified;
            IEnumerable <Mutation>   mutations = new List <Mutation>();
            // Make the request
            CommitResponse response = datastoreClient.Commit(projectId, mode, mutations);
            // End snippet
        }
示例#4
0
        /// <summary>Snippet for Commit</summary>
        public void Commit1()
        {
            // Snippet: Commit(string, CommitRequest.Types.Mode, ByteString, IEnumerable<Mutation>, CallSettings)
            // Create client
            DatastoreClient datastoreClient = DatastoreClient.Create();
            // Initialize request argument(s)
            string projectId = "";

            CommitRequest.Types.Mode mode      = CommitRequest.Types.Mode.Unspecified;
            ByteString             transaction = ByteString.Empty;
            IEnumerable <Mutation> mutations   = new Mutation[] { new Mutation(), };
            // Make the request
            CommitResponse response = datastoreClient.Commit(projectId, mode, transaction, mutations);
            // End snippet
        }
        /// <summary>Snippet for Commit</summary>
        public void Commit1()
        {
            // Snippet: Commit(string,CommitRequest.Types.Mode,ByteString,IEnumerable<Mutation>,CallSettings)
            // Create client
            DatastoreClient datastoreClient = DatastoreClient.Create();
            // Initialize request argument(s)
            string projectId = "";

            CommitRequest.Types.Mode mode      = CommitRequest.Types.Mode.Unspecified;
            ByteString             transaction = Google.Protobuf.ByteString.CopyFromUtf8("");
            IEnumerable <Mutation> mutations   = new List <Mutation>();
            // Make the request
            CommitResponse response = datastoreClient.Commit(projectId, mode, transaction, mutations);
            // End snippet
        }
        // Used by TransactionReadAndWrite. Could promote to the fixture.
        private Key CreateAccount(string name, long balance)
        {
            string          projectId   = _fixture.ProjectId;
            string          namespaceId = _fixture.NamespaceId;
            DatastoreClient client      = DatastoreClient.Create();
            KeyFactory      factory     = new KeyFactory(projectId, namespaceId, "Account");
            Entity          entity      = new Entity
            {
                Key         = factory.CreateIncompleteKey(),
                ["name"]    = name,
                ["balance"] = balance
            };
            CommitResponse response = client.Commit(projectId, Mode.NonTransactional, new[] { entity.ToInsert() });

            return(response.MutationResults[0].Key);
        }
示例#7
0
 public void Commit_RequestObject()
 {
     // Snippet: Commit(CommitRequest,CallSettings)
     // Create client
     DatastoreClient datastoreClient = DatastoreClient.Create();
     // Initialize request argument(s)
     CommitRequest request = new CommitRequest
     {
         ProjectId = "",
         Mode      = CommitRequest.Types.Mode.Unspecified,
         Mutations = { },
     };
     // Make the request
     CommitResponse response = datastoreClient.Commit(request);
     // End snippet
 }
        public void InsertEntity()
        {
            string projectId   = _fixture.ProjectId;
            string namespaceId = _fixture.NamespaceId;

            // Sample: InsertEntity
            KeyFactory keyFactory = new KeyFactory(projectId, namespaceId, "Task");
            Entity     entity     = new Entity
            {
                Key                  = keyFactory.CreateIncompleteKey(),
                ["category"]         = "Personal",
                ["done"]             = false,
                ["priority"]         = 4,
                ["description"]      = "Learn Cloud Datastore",
                ["percent_complete"] = 75.0
            };
            DatastoreClient client      = DatastoreClient.Create();
            CommitResponse  response    = client.Commit(projectId, Mode.NonTransactional, new[] { entity.ToInsert() });
            Key             insertedKey = response.MutationResults[0].Key;
            // End sample
        }