forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvertisementRepository.cs
More file actions
68 lines (60 loc) · 1.81 KB
/
AdvertisementRepository.cs
File metadata and controls
68 lines (60 loc) · 1.81 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Blog.Core.IRepository;
using Blog.Core.Model.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Blog.Core.Repository
{
public class AdvertisementRepository : IAdvertisementRepository
{
private DbContext context;
private SqlSugarClient db;
private SimpleClient<Advertisement> entityDB;
internal SqlSugarClient Db
{
get { return db; }
private set { db = value; }
}
public DbContext Context
{
get { return context; }
set { context = value; }
}
public AdvertisementRepository()
{
DbContext.Init(BaseDBConfig.ConnectionString);
context = DbContext.GetDbContext();
db = context.Db;
entityDB = context.GetEntityDB<Advertisement>(db);
}
public int Add(Advertisement model)
{
//返回的i是long类型,这里你可以根据你的业务需要进行处理
var i = db.Insertable(model).ExecuteReturnBigIdentity();
return i.ObjToInt();
}
public bool Delete(Advertisement model)
{
var i = db.Deleteable(model).ExecuteCommand();
return i > 0;
}
public List<Advertisement> Query(Expression<Func<Advertisement, bool>> whereExpression)
{
return entityDB.GetList(whereExpression);
}
public int Sum(int i, int j)
{
return i + j;
}
public bool Update(Advertisement model)
{
//这种方式会以主键为条件
var i = db.Updateable(model).ExecuteCommand();
return i > 0;
}
}
}