forked from liaozb/APIJSON.NET
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDbContext.cs
More file actions
41 lines (37 loc) · 1.15 KB
/
DbContext.cs
File metadata and controls
41 lines (37 loc) · 1.15 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
using APIJSON.Data.Models;
using Microsoft.Extensions.Configuration;
using SqlSugar;
using System;
using System.Collections.Generic;
using Volo.Abp.DependencyInjection;
namespace APIJSON.Data;
public class DbContext:ISingletonDependency
{
public DbContext(IConfiguration options)
{
Db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = options.GetConnectionString("ConnectionString"),
DbType = (DbType)Enum.Parse(typeof(DbType), options.GetConnectionString("DbType")), InitKeyType= InitKeyType.Attribute,
IsAutoCloseConnection = true
});
Db.Aop.OnLogExecuted = (sql, pars) => //SQL执行完事件
{
};
Db.Aop.OnLogExecuting = (sql, pars) => //SQL执行前事件
{
};
}
public SqlSugarClient Db;
public DbSet<Login> LoginDb { get { return new DbSet<Login>(Db); } }
}
public class DbSet<T> : SimpleClient<T> where T : class, new()
{
public DbSet(SqlSugarClient context) : base(context)
{
}
public List<T> GetByIds(dynamic[] ids)
{
return Context.Queryable<T>().In(ids).ToList(); ;
}
}