Exemplo n.º 1
0
 protected virtual async Task ExecuteAsync(Func <CancellationToken, Task> action, CancellationToken cancellationToken)
 {
     using (dataContext = new DataContext(EfDbContext.SetupOptionsWithConnectionString(_loggerFactory, _connectionString, EnableProxies)))
     {
         await action(cancellationToken);
     }
 }
Exemplo n.º 2
0
        private Product GetFirstProductDisconnected()
        {
            using (var db = new DataContext(EfDbContext.SetupOptionsWithConnectionString(_loggerFactory, _connectionString)))
            {
                var product = db.Products.Include(x => x.Reviews)
                              .FirstOrDefault(x => x.Reviews.Any());

                foreach (var review in product.Reviews)
                {
                    review.NumStars = 5;
                }
                return(product);
            }
        }
Exemplo n.º 3
0
        protected override async Task ExecuteAsync(Func <CancellationToken, Task> action, CancellationToken cancellationToken)
        {
            if (!UseDapper)
            {
                using (dataContext = new DataContext(EfDbContext.SetupOptionsWithConnectionString(_loggerFactory, _connectionString, EnableProxies)))
                {
                    var products = await dataContext.Products.FromSql("select p.* from Products p where (select count(1) from Reviews r where r.ProductId = p.Id) > 5").ToListAsync(cancellationToken);
                }
            }
            else
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();
                    var query     = "select p.* from Products p where (select count(1) from Reviews r where r.ProductId=p.Id) > 5";
                    var stopwatch = Stopwatch.StartNew();
                    Console.WriteLine("Dapper. Executing query: \"" + query + "\"");
                    var products = await connection.QueryAsync(new CommandDefinition(query, cancellationToken : cancellationToken ));

                    stopwatch.Stop();
                    Console.WriteLine("Dapper: command executed in " + stopwatch.Elapsed.TotalMilliseconds.ToString() + " MS.");
                }
            }
        }