兼容win7版应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.6 KiB

using System.Data.SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AIK.DataAccess
{
public class SqlitePooledConnection : IDisposable
{
// 内部持有真实的 SQLite 连接
private readonly SQLiteConnection _innerConnection;
// 标记是否已释放
private bool _disposed = false;
/// <summary>
/// 暴露内部连接供 Dapper 调用(核心)
/// </summary>
public SQLiteConnection InnerConnection => _innerConnection;
/// <summary>
/// 构造函数(仅由 SQLiteCore 内部创建,外部不直接实例化)
/// </summary>
internal SqlitePooledConnection(SQLiteConnection innerConnection)
{
_innerConnection = innerConnection ?? throw new ArgumentNullException(nameof(innerConnection));
}
/// <summary>
/// using 结束时自动执行,归还连接到池
/// </summary>
public void Dispose()
{
if (!_disposed)
{
// 关键:归还连接到连接池,而非销毁
SQLiteCore.ReturnConnection(_innerConnection);
_disposed = true;
}
}
// 可选:暴露常用方法,简化调用(如创建命令)
public SQLiteCommand CreateCommand()
{
if (_disposed) throw new ObjectDisposedException(nameof(SqlitePooledConnection));
return _innerConnection.CreateCommand();
}
}
}