Esempio n. 1
0
        static void TestRun1()
        {
            //Azure Storage account and Table Service Instances
            CloudStorageAccount storageAccount;
            CloudTableClient    tableClient;

            //connect to storage account
            storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");

            //create the table 'Book' if it not exists
            tableClient = storageAccount.CreateCloudTableClient();
            CloudTable cloudTable = tableClient.GetTableReference("Book");

            cloudTable.CreateIfNotExistsAsync();

            BookEntity aNewBook = new BookEntity()
            {
                Author = "Rami", BookName = "ASP.NET Core with Azure", Publisher = "APress"
            };

            aNewBook.BookId       = 3;
            aNewBook.RowKey       = aNewBook.BookId.ToString();
            aNewBook.PartitionKey = aNewBook.Publisher;
            aNewBook.CreatedDate  = DateTime.UtcNow;
            aNewBook.UpdatedDate  = DateTime.UtcNow;

            //insert and execute operations
            TableOperation insertOperation = TableOperation.Insert(aNewBook);

            cloudTable.ExecuteAsync(insertOperation);
        }
Esempio n. 2
0
        static async void TestAddWithUnitOfWork(string partition, string row)
        {
            using (var _unitOfWork = new UnitOfWork("UseDevelopmentStorage=true"))
            {
                var bookRepository = _unitOfWork.Repository <BookEntity>();
                await bookRepository.CreateTableAsync();

                BookEntity book = new BookEntity()
                {
                    BookId    = int.Parse(row),
                    Author    = "Rami",
                    BookName  = "ASP.NET Core with Azure",
                    Publisher = partition
                };
                book.RowKey       = book.BookId.ToString();
                book.PartitionKey = book.Publisher;
                var data = await bookRepository.FindAsync(book.PartitionKey, book.RowKey);

                if (null == data)
                {
                    data = await bookRepository.AddAsync(book);

                    Console.WriteLine(data);
                }

                _unitOfWork.CommitTransactions();
            }
        }