Esempio n. 1
0
        private static async Task MainAsync(string[] args)
        {
            var factory = new UnitOfWorkFactory(ConnectionString);

            using (var uow = await factory.CreateAsync(retryOptions: new RetryOptions(5, 100, new SqlTransientExceptionDetector())))
            {
                var customer = await uow.QueryAsync(new GetCustomerByIdQuery("ALFKI"));

                Console.WriteLine($"Retrieved asynchronously: {customer.CompanyName}");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// asynchronously retrieve one match from Peoples table in the database using its Id
 /// </summary>
 /// <param name="Id"></param>
 private async static Task PrintPersonAsync(int Id)
 {
     try
     {
         var factory = new UnitOfWorkFactory(ConnectionString);
         using (var uow = await factory.CreateAsync(true))
         {
             // find one person by its address street's name
             var personOne = (await uow.GetAsync(new GetPersonByStreetCommand <int>(Id))).FirstOrDefault();
             Console.WriteLine($"Person: {personOne?.Name} ({personOne?.Address?.Street})");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// asynchronously retrive all the entries from Peoples table in the database
        /// </summary>
        private async static Task PrintPeopleAsync()
        {
            try
            {
                var factory = new UnitOfWorkFactory(ConnectionString);
                using (var uow = await factory.CreateAsync(true))
                {
                    // fetch all the people in the database
                    var people = await uow.GetAsync(new GetPeopleCommand());

                    foreach (var p in people)

                    {
                        Console.WriteLine($"Person: {p?.Name} ({p?.Address?.Street})");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// asynchronously remove an entry from the database
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        private async static Task RemovePersonAsync(int Id)
        {
            try
            {
                // initialize the connection builder
                var factory = new UnitOfWorkFactory(ConnectionString);
                // initialize the repository with transactions set to true
                using (var uow = await factory.CreateAsync(true))
                {
                    // executes the command
                    var result = await uow.DeleteAsync(new DeletePersonByIdCommand(6));

                    // prints the affected rows
                    Console.WriteLine($"Deleted: {result}");
                    // commits the changes
                    uow.Commit();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }