public async Task <TKey> InsertOneAsync(TEntity dsEntity) { var entity = BuildEntity(dsEntity); var keys = await _database.InsertAsync(new[] { entity }); if (keys.Any() && keys[0] == null) { return(GetId(dsEntity)); } // Auto-generated key - set the key property under the entity var id = GetId(keys.FirstOrDefault()); SetId(dsEntity, id); return(id); }
public async Task AddEntity_NonTransactional_Async() { string projectId = _fixture.ProjectId; string namespaceId = _fixture.NamespaceId; // Snippet: InsertAsync(*) DatastoreDb db = DatastoreDb.Create(projectId, namespaceId); KeyFactory keyFactory = db.CreateKeyFactory("book"); Entity book1 = new Entity { Key = keyFactory.CreateIncompleteKey(), ["author"] = "Harper Lee", ["title"] = "To Kill a Mockingbird", ["publication_date"] = new DateTime(1960, 7, 11, 0, 0, 0, DateTimeKind.Utc), ["genres"] = new[] { "Southern drama", "Courtroom drama", "Bildungsroman" } }; Entity book2 = new Entity { Key = keyFactory.CreateIncompleteKey(), ["author"] = "Charlotte Brontë", ["title"] = "Jane Eyre", ["publication_date"] = new DateTime(1847, 10, 16, 0, 0, 0, DateTimeKind.Utc), ["genres"] = new[] { "Gothic", "Romance", "Bildungsroman" } }; IReadOnlyList <Key> insertedKeys = await db.InsertAsync(book1, book2); Console.WriteLine($"Inserted keys: {string.Join(",", insertedKeys)}"); // End snippet }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } string projectId = Configuration["GoogleProjectId"]; if (new string[] { "your-project-id", "", null }.Contains(projectId)) { app.Run(async(context) => { await context.Response.WriteAsync(@"<html> <head><title>Error</title></head> <body><p>Set GoogleProjectId to your project id in appsettings.json. <p>See the README.md in the project directory for more information.</p> </body> </html>"); }); return; } // [START example] DatastoreDb datastore = DatastoreDb.Create(projectId); var visitKeyFactory = datastore.CreateKeyFactory("visit"); // [END example] app.Run(async(HttpContext context) => { // [START example] // Insert a visit into Datastore: Entity newVisit = new Entity(); newVisit.Key = visitKeyFactory.CreateIncompleteKey(); newVisit["time_stamp"] = DateTime.UtcNow; newVisit["ip_address"] = FormatAddress( context.Connection.RemoteIpAddress); await datastore.InsertAsync(newVisit); // Look up the last 10 visits. var results = await datastore.RunQueryAsync(new Query("visit") { Order = { { "time_stamp", PropertyOrder.Types.Direction.Descending } }, Limit = 10 }); await context.Response.WriteAsync(@"<html> <head><title>Visitor Log</title></head> <body>Last 10 visits:<br>"); foreach (Entity visit in results.Entities) { await context.Response.WriteAsync(string.Format("{0} {1}<br>", visit["time_stamp"].TimestampValue, visit["ip_address"].StringValue)); } await context.Response.WriteAsync(@"</body></html>"); // [END example] }); }
public async Task <Guid> Insert(string into, IDataEntityObject item) { var entity = new Entity() { Key = _db.CreateKeyFactory(into).CreateIncompleteKey(), }; foreach (var propKey in item.Keys()) { entity[propKey] = item.Get <string>(propKey); } var keys = await _db.InsertAsync(new[] { entity }).ConfigureAwait(false); return(item.Id); }
private async Task <Key> AddGameState(GameState item) { var entity = ConvertToEntity(item); return(await _db.InsertAsync(entity)); }
/// <summary> /// Async insert /// </summary> /// <param name="poco">The POCO to insert</param> /// <param name="kind">The kind to work on</param> public virtual Task InsertAsync <TPoco>(TPoco poco, string kind) { return(datastoreDb.InsertAsync(orm.PocoToEntity(poco, kind))); }
public async Task <IdentityResult> CreateAsync(R role, CancellationToken cancellationToken) { return(await Rpc.TranslateExceptionsAsync(() => _datastore.InsertAsync(RoleToEntity(role), CallSettings.FromCancellationToken(cancellationToken)))); }