17 lines
526 B
C#
17 lines
526 B
C#
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
||
|
namespace BITKit;
|
||
|
|
||
|
public class SqlLiteContext<T> : DbContext where T : class
|
||
|
{
|
||
|
private const string _database = "Database";
|
||
|
public DbSet<T> context { get; private set; }
|
||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||
|
{
|
||
|
PathHelper.GetFolderPath(_database);
|
||
|
var path = PathHelper.GetPath(_database, $"{typeof(T).Name}.db");
|
||
|
var sql = $"Data Source={path}";
|
||
|
BIT4Log.Log<T>($"已创建数据库链接:{path}");
|
||
|
optionsBuilder.UseSqlite(sql);
|
||
|
}
|
||
|
}
|