Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

丁松杰 / Pole

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Switch branch/tag
  • Pole
  • test
  • Pole.Samples.Backet.Api
  • Benchmarks
  • GrainWithEntityframeworkCoreAndPgTest.cs
Find file
BlameHistoryPermalink
  • dingsongjie's avatar
    性能部分 改进完成 · b9422953
    dingsongjie committed 5 years ago
    b9422953
GrainWithEntityframeworkCoreAndPgTest.cs 1.83 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
using Backet.Api.Infrastructure;
using BenchmarkDotNet.Attributes;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Dapper;

namespace Pole.Samples.Backet.Api.Benchmarks
{
    public class GrainWithEntityframeworkCoreAndPgTest
    {
        IServiceProvider serviceProvider;
        public GrainWithEntityframeworkCoreAndPgTest()
        {
            var services = new ServiceCollection();
            services.AddDbContextPool<BacketDbContext>(options => options.UseNpgsql("Server=192.168.0.248;Port=5432;Username=postgres;Password=comteck2020!@#;Database=Pole-Backet;Enlist=True;Timeout=0;Command Timeout=600;MinPoolSize=20;MaxPoolSize=500;"));
            serviceProvider = services.BuildServiceProvider();
        }
        [Benchmark]
        public async Task SingleOrDefaultAsync()
        {
            using (var scope = serviceProvider.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService<BacketDbContext>();

                var entity = await context.Backets.Include(box => box.BacketItems).SingleOrDefaultAsync(m => m.Id == "222");
            }
        }
        [Benchmark]
        public async Task DapperOpenConnection()
        {
            using (NpgsqlConnection conn = new NpgsqlConnection("Server=192.168.0.251;Port=5432;Username=postgres;Password=comteck2020!@#;Database=smartretail-tenant;Enlist=True;"))
            {
                await conn.OpenAsync();
                //var teams = await conn.QueryAsync<Backet.Api.Domain.AggregatesModel.BacketAggregate.Backet>("SELECT * FROM   \"public\".\"Backet\" where  \"Id\" =@Id", new { Id = newId });
                var teams = await conn.ExecuteAsync("SELECT 1");
            }
        }
    }
}