1
0

練習資料庫紀錄完成

This commit is contained in:
2024-03-25 18:18:41 +08:00
parent 3382627c8c
commit 088ec7620a
17 changed files with 119 additions and 22 deletions

View File

@@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="coreprofiler" Version="1.1.4" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.3" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreProfilerExample.Common
{
public interface IDatabaseOption
{
public IDbConnection SqliteConnection { get; }
}
}

View File

@@ -0,0 +1,30 @@
using CoreProfiler;
using CoreProfiler.Data;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CoreProfilerExample.Common.Options
{
public class DatabaseOption(IConfiguration configuration) : IDatabaseOption
{
public IDbConnection SqliteConnection
{
get
{
var connectionString = configuration.GetConnectionString("SQLITE");
var dbProfiler = ProfilingSession.Current != null
? new DbProfiler(ProfilingSession.Current.Profiler)
: null;
return new ProfiledDbConnection(new SqliteConnection(connectionString), dbProfiler);
}
}
}
}