public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null) { Console.WriteLine(""); Console.WriteLine(this.GetType().FullName); using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix)) { // set the delegate var stats = new DemoCaseStatsDelegate(); storageContext.SetDelegate(stats); // create a new user var user = new UserModel2() { FirstName = "Egon", LastName = "Mueller", Contact = "*****@*****.**" }; var vpmodel = new VirtualPartKeyDemoModel() { Value1 = "abc", Value2 = "def", Value3 = "ghi" }; // ensure we are using the attributes Console.WriteLine("Configuring Entity Mappers"); storageContext.AddAttributeMapper(typeof(UserModel2)); storageContext.AddAttributeMapper(typeof(VirtualPartKeyDemoModel)); // ensure the table exists Console.WriteLine("Create Tables"); await storageContext.CreateTableAsync <UserModel2>(); await storageContext.CreateTableAsync <VirtualPartKeyDemoModel>(); // inser the model Console.WriteLine("Insert Models"); await storageContext.MergeOrInsertAsync <UserModel2>(user); await storageContext.MergeOrInsertAsync <VirtualPartKeyDemoModel>(vpmodel); // query all Console.WriteLine("Query all Models"); var result = await storageContext.QueryAsync <UserModel2>(); var resultVP = await storageContext.QueryAsync <VirtualPartKeyDemoModel>(); foreach (var r in result) { Console.WriteLine(r.FirstName); } // Clean up Console.WriteLine("Removing all entries"); await storageContext.DeleteAsync <UserModel2>(result); await storageContext.DeleteAsync <VirtualPartKeyDemoModel>(resultVP); // dump the stats stats.DumpStats(); } }
public string CreateUser(UserModel2 user) { // Create User Object return("value create: " + user.Name + " - age: " + user.Age + " - cars[0]: " + user.Cars[0]); }
public async Task Execute(string storageKey, string storageSecret, string endpointSuffix = null) { Console.WriteLine(""); Console.WriteLine(this.GetType().FullName); using (var storageContext = new StorageContext(storageKey, storageSecret, endpointSuffix)) { // set the delegate var stats = new DemoCaseStatsDelegate(); storageContext.SetDelegate(stats); // ensure we are using the attributes Console.WriteLine("Configuring Entity Mappers"); storageContext.AddAttributeMapper(typeof(UserModel2), "DemoUserModel2"); // create tables Console.WriteLine("Create Tables"); await storageContext.CreateTableAsync <UserModel2>(true); // write data pages Console.WriteLine("Writing Models Paged"); var startDate = DateTime.Now; using (var pagedWriter = new PagedTableEntityWriter <UserModel2>(storageContext, nStoreOperation.insertOrReplaceOperation, 100)) { var t1 = Task.Run(async() => { for (var i = 0; i < 500; i++) { var user = new UserModel2() { FirstName = "Egon", LastName = "Mueller", Contact = string.Format("em-{0}@acme.org", i) }; await pagedWriter.StoreAsync(user); } }); var t2 = Task.Run(async() => { for (var i = 500; i < 1000; i++) { var user = new UserModel2() { FirstName = "Egon", LastName = "Mueller", Contact = string.Format("em-{0}@acme.org", i) }; await pagedWriter.StoreAsync(user); } }); Task.WaitAll(new Task[] { t1, t2 }); } var endDate = DateTime.Now; Console.WriteLine("Took {0} seconds", (endDate - startDate).TotalSeconds); // query all Console.WriteLine("Query all Models"); var result = await storageContext.QueryAsync <UserModel2>(); Console.WriteLine("Found {0} models", result.Count()); // Clean up Console.WriteLine("Removing all entries"); await storageContext.DeleteAsync <UserModel2>(result); // dump the stats stats.DumpStats(); } }