C#基于Autocad的二次开发(9.Sqlsugar仓储模式)

开始之前确保已完成步骤1创建解决方案和类库项目,并在对应项目中安装nuget包

Sqlsugar介绍

SqlSugar是一个开源的ORM框架,支持. NET Core/.NET Framework/Mono/Xamarin。 它是一个轻量级、易于使用、高性能的ORM框架,具有较强的扩展性。 SqlSugar不仅提供基础的CRUD操作,还提供了更高级的查询操作,如多表联查、分页、分组、聚合等功能。更多介绍和文档参阅官网。

配置项实体

ACD.Domain项目中创建DbConfig配置的实体类

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
/// <summary>
/// ACDesign 数据库配置
/// </summary>
public class ACDesignDbConfig
{
/// <summary>
/// 连接名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 连接字符串
/// </summary>
public string ConnectionString { get; set; }

public bool Default { get; set; }
public bool IsAutoCloseConnection { get; set; }

public DbType DbType { get; set; }

public ACDesignDbConfig() { }

public ACDesignDbConfig(string name, string connectionString, bool @default, bool isAutoCloseConnection, DbType dbType)
{
Name = name;
ConnectionString = connectionString;
Default = @default;
IsAutoCloseConnection = isAutoCloseConnection;
DbType = dbType;
}
}

ACD.Domain项目中配置项AppSettingConfig中加入数据库配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// <summary>
/// 配置项
/// </summary>
public class AppSettingConfig
{
/// <summary>
/// 数据库配置
/// </summary>
public ACDesignDbConfig ACDesignDbConfig { get; set; }

/// <summary>
/// hangfire 数据库连接
/// </summary>
public string HangfireStorage { get; set; }
}

抽象约束

ACD.Domain项目中添加对数据库表对应的实体类约束:
创建ISoftDelete.cs接口文件

1
2
3
4
5
public interface ISoftDelete
{
DateTime? DeletedOn { get; set; }
bool IsDeleted { get; set; }
}

创建IEntity接口文件

1
2
3
4
5
6
public interface IEntity {  }

public interface IEntity<TId> : IEntity
{
TId Id { get; }
}

创建IAuditableEntity接口文件

1
2
3
4
5
public interface IAuditableEntity
{
DateTime CreatedOn { get; }
DateTime? LastModifiedOn { get; set; }
}

创建BaseEntity抽象类

1
2
3
4
5
6
7
8
9
10
public abstract class BaseEntity : BaseEntity<Guid>
{
protected BaseEntity() => Id = Guid.NewGuid();
}

public abstract class BaseEntity<TId> : IEntity<TId>
{
[SugarColumn(IsPrimaryKey = true)]
public TId Id { get; set; }
}

创建AuditableEntity抽象类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public abstract class AuditableEntity : AuditableEntity<Guid>
{
protected AuditableEntity() => Id = Guid.NewGuid();
}

public abstract class AuditableEntity<T> : BaseEntity<T>, IAuditableEntity, ISoftDelete
{
public DateTime CreatedOn { get; private set; }
public DateTime? LastModifiedOn { get; set; }
public DateTime? DeletedOn { get; set; }
public bool IsDeleted { get; set; }

protected AuditableEntity()
{
CreatedOn = DateTime.Now;
IsDeleted = false;
}
}

ACD.Application项目中创建泛型接口IDbRepository

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
public interface IDbRepository<T>
where T : class, ISoftDelete, IAuditableEntity, new()
{
ISugarQueryable<T> AsQueryable();
IInsertable<T> AsInsertable(T insertObj);
IInsertable<T> AsInsertable(T[] insertObjs);
IInsertable<T> AsInsertable(List<T> insertObjs);
IUpdateable<T> AsUpdateable(T updateObj);
IUpdateable<T> AsUpdateable(T[] updateObjs);
IUpdateable<T> AsUpdateable(List<T> updateObjs);
IDeleteable<T> AsDeleteable();

List<T> GetList();
Task<List<T>> GetListAsync();
List<T> GetList(Expression<Func<T, bool>> whereExpression);
Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression);
List<T> GetList(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page);
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page);
List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc);

int Count(Expression<Func<T, bool>> whereExpression);
Task<int> CountAsync(Expression<Func<T, bool>> whereExpression);
T GetById(dynamic id);
T GetSingle(Expression<Func<T, bool>> whereExpression);
Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression);
T GetFirst(Expression<Func<T, bool>> whereExpression);
Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);

bool IsAny(Expression<Func<T, bool>> whereExpression);
Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression);

bool Insert(T insertObj);
Task<bool> InsertAsync(T insertObj);
bool InsertRange(List<T> insertObjs);
Task<bool> InsertRangeAsync(List<T> insertObjs);
bool InsertRange(T[] insertObjs);
Task<bool> InsertRangeAsync(T[] insertObjs);
int InsertReturnIdentity(T insertObj);
Task<long> InsertReturnIdentityAsync(T insertObj);

bool Delete(Expression<Func<T, bool>> whereExpression);
Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression);
bool Delete(T deleteObj);
Task<bool> DeleteAsync(T deleteObj);
bool DeleteById(dynamic id);
Task<bool> DeleteByIdAsync(dynamic id);
bool DeleteByIds(dynamic[] ids);
Task<bool> DeleteByIdsAsync(dynamic[] ids);

bool Update(T t, Expression<Func<T, object>> columns, Expression<Func<T, bool>> whereExpression);
Task<bool> UpdateAsync(T t, Expression<Func<T, object>> columns, Expression<Func<T, bool>> whereExpression);
bool Update(T updateObj);
Task<bool> UpdateAsync(T updateObj);
bool UpdateRange(T[] updateObjs);
Task<bool> UpdateRangeAsync(T[] updateObjs);

DbResult<T2> UseTran<T2>(Func<T2> action);
DbResult<bool> UseTran(Action action);
Task<DbResult<T2>> UseTranAsync<T2>(Func<Task<T2>> action, Action<Exception> errorCallBack = null);
Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null);

void BeginTran();
void CommitTran();
void RollbackTran();
}

实现

ACD.Infrastructure项目中添加类文件DbConnectOption.cs,继承自Sqlsugar配置ConnectionConfig

1
2
3
4
5
6
7
8
9
10
11
public class DbConnectOption:ConnectionConfig
{
/// <summary>
/// 数据库连接名称
/// </summary>
public string Name { set; get; }
/// <summary>
/// 是否默认库
/// </summary>
public bool Default { set; get; }
}

ACD.Infrastructure项目中添加类文件ACDSqlSugarClient,继承自Sqlsugar客户端SqlSugarClient

1
2
3
4
5
6
7
8
9
10
public class ACDSqlSugarClient : SqlSugarClient
{
public ACDSqlSugarClient(DbConnectOption config) : base(config)
{
DbName = config.Name;
Default = config.Default;
}
public string DbName { set; get; }
public bool Default { set; get; }
}

ACD.Infrastructure项目中添加类文件DbRepository.cs实现自IDbRepository

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
public class DbRepository<T>:IDbRepository<T>
where T : class, ISoftDelete, IAuditableEntity, new()
{
private readonly ACDSqlSugarClient DbContext;

public DbRepository(ACDSqlSugarClient client)
{
DbContext = client;
}

public ISugarQueryable<T> AsQueryable()
{
return DbContext.Queryable<T>().Where(x => !x.IsDeleted);
}

public IInsertable<T> AsInsertable(T insertObj)
{
return DbContext.Insertable(insertObj);
}

public IInsertable<T> AsInsertable(T[] insertObjs)
{
return DbContext.Insertable(insertObjs);
}

public IInsertable<T> AsInsertable(List<T> insertObjs)
{
return DbContext.Insertable(insertObjs);
}

public IUpdateable<T> AsUpdateable(T updateObj)
{
return DbContext.Updateable(updateObj);
}

public IUpdateable<T> AsUpdateable(T[] updateObjs)
{
return DbContext.Updateable(updateObjs);
}

public IUpdateable<T> AsUpdateable(List<T> updateObjs)
{
return DbContext.Updateable(updateObjs);
}

public IDeleteable<T> AsDeleteable()
{
return DbContext.Deleteable<T>();
}
public IDeleteable<T> AsDeleteable(T deleteObj)
{
return DbContext.Deleteable(deleteObj);
}

public List<T> GetList()
{
return AsQueryable().ToList();
}

public Task<List<T>> GetListAsync()
{
return AsQueryable().ToListAsync();
}

public List<T> GetList(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().Where(whereExpression).ToList();
}

public Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().Where(whereExpression).ToListAsync();
}

public List<T> GetList(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
return AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToList();
}

public Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
return AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToListAsync();
}

public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page)
{
int count = 0;
var result = AsQueryable().Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
page.TotalCount = count;
return result;
}

public Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page)
{
RefAsync<int> count = 0;
var result = AsQueryable().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
page.TotalCount = count;
return result;
}

public List<T> GetPageList(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
int count = 0;
var result = AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageList(page.PageIndex, page.PageSize, ref count);
page.TotalCount = count;
return result;
}

public Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
RefAsync<int> count = 0;
var result = AsQueryable().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
page.TotalCount = count;
return result;
}

public int Count(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().Count(whereExpression);
}

public Task<int> CountAsync(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().CountAsync(whereExpression);
}

public T GetById(dynamic id)
{
return AsQueryable().InSingle(id);
}

public T GetSingle(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().Single(whereExpression);
}

public Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().SingleAsync(whereExpression);
}

public T GetFirst(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().First(whereExpression);
}

public Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().FirstAsync(whereExpression);
}

public bool IsAny(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().Any(whereExpression);
}

public Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression)
{
return AsQueryable().AnyAsync(whereExpression);
}

public bool Insert(T insertObj)
{
return AsInsertable(insertObj).ExecuteCommand() > 0;
}

public async Task<bool> InsertAsync(T insertObj)
{
return await AsInsertable(insertObj).ExecuteCommandAsync() > 0;
}

public bool InsertRange(List<T> insertObjs)
{
return AsInsertable(insertObjs).ExecuteCommand() > 0;
}

public async Task<bool> InsertRangeAsync(List<T> insertObjs)
{
return await AsInsertable(insertObjs).ExecuteCommandAsync() > 0;
}

public bool InsertRange(T[] insertObjs)
{
return AsInsertable(insertObjs).ExecuteCommand() > 0;
}

public async Task<bool> InsertRangeAsync(T[] insertObjs)
{
return await AsInsertable(insertObjs).ExecuteCommandAsync() > 0;
}

public int InsertReturnIdentity(T insertObj)
{
return AsInsertable(insertObj).ExecuteReturnIdentity();
}

public Task<long> InsertReturnIdentityAsync(T insertObj)
{
return AsInsertable(insertObj).ExecuteReturnBigIdentityAsync();
}

public bool Delete(Expression<Func<T, bool>> whereExpression)
{
return AsDeleteable().Where(whereExpression).ExecuteCommandHasChange();
}

public Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression)
{
return AsDeleteable().Where(whereExpression).ExecuteCommandHasChangeAsync();
}

public bool Delete(T deleteObj)
{
return AsDeleteable(deleteObj).ExecuteCommandHasChange();
}

public Task<bool> DeleteAsync(T deleteObj)
{
return AsDeleteable(deleteObj).ExecuteCommandHasChangeAsync();
}

public bool DeleteById(dynamic id)
{
return AsDeleteable().In(id).ExecuteCommandHasChange();
}

public Task<bool> DeleteByIdAsync(dynamic id)
{
return AsDeleteable().In(id).ExecuteCommandHasChangeAsync();
}

public bool DeleteByIds(dynamic[] ids)
{
return AsDeleteable().In(ids).ExecuteCommandHasChange();
}

public Task<bool> DeleteByIdsAsync(dynamic[] ids)
{
return AsDeleteable().In(ids).ExecuteCommandHasChangeAsync();
}

public bool Update(T t, Expression<Func<T, object>> columns, Expression<Func<T, bool>> whereExpression)
{
return AsUpdateable(t).UpdateColumns(columns).Where(whereExpression).ExecuteCommandHasChange();
}

public Task<bool> UpdateAsync(T t, Expression<Func<T, object>> columns, Expression<Func<T, bool>> whereExpression)
{
return AsUpdateable(t).UpdateColumns(columns).Where(whereExpression).ExecuteCommandHasChangeAsync();
}

public bool Update(T updateObj)
{
return AsUpdateable(updateObj).ExecuteCommandHasChange();
}

public Task<bool> UpdateAsync(T updateObj)
{
return AsUpdateable(updateObj).ExecuteCommandHasChangeAsync();
}

public bool UpdateRange(T[] updateObjs)
{
return AsUpdateable(updateObjs).ExecuteCommandHasChange();
}

public Task<bool> UpdateRangeAsync(T[] updateObjs)
{
return AsUpdateable(updateObjs).ExecuteCommandHasChangeAsync();
}

public DbResult<T2> UseTran<T2>(Func<T2> action)
{
return DbContext.Ado.UseTran(action);
}

public DbResult<bool> UseTran(Action action)
{
return DbContext.Ado.UseTran(action);
}

public Task<DbResult<T2>> UseTranAsync<T2>(Func<Task<T2>> action, Action<Exception> errorCallBack = null)
{
return DbContext.Ado.UseTranAsync(action, errorCallBack);
}

public Task<DbResult<bool>> UseTranAsync(Func<Task> action, Action<Exception> errorCallBack = null)
{
return DbContext.Ado.UseTranAsync(action, errorCallBack);
}

public void BeginTran()
{
DbContext.Ado.BeginTran();
}

public void CommitTran()
{
DbContext.Ado.CommitTran();
}

public void RollbackTran()
{
DbContext.Ado.RollbackTran();
}
}

注入

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
public static class Startup
{
public static ContainerBuilder AddInfrastructure(this ContainerBuilder builder,AppSettingConfig config)
{
builder.RegisterModule<NLogModule>();

return builder
.AddDbClient(
new DbConnectOption
{
DbType = config.ACDesignDbConfig.DbType,
Name= config.ACDesignDbConfig.Name,
Default=config.ACDesignDbConfig.Default,
ConnectionString= config.ACDesignDbConfig.ConnectionString,
IsAutoCloseConnection = config.ACDesignDbConfig.IsAutoCloseConnection
}
)
.AddDbRepository()
.AddServices();
}

internal static ContainerBuilder AddDbClient(this ContainerBuilder builder, DbConnectOption dbConfig)
{
if (dbConfig.IsNull()) throw new InternalServerException("请配置数据库连接");

//单例
builder.RegisterInstance(new ACDSqlSugarClient(dbConfig))
.SingleInstance();

return builder;
}

internal static ContainerBuilder AddDbRepository(this ContainerBuilder builder)
{
builder.RegisterGeneric(typeof(DbRepository<>))
.As(typeof(IDbRepository<>))
.InstancePerLifetimeScope();

return builder;
}

public static BackgroundJobServer AddHangfireService(this IGlobalConfiguration configuration, AppSettingConfig config)
{
configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseSqlServerStorage(config.HangfireStorage, new SqlServerStorageOptions
{
CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
QueuePollInterval = TimeSpan.Zero,
UseRecommendedIsolationLevel = true
});

return new BackgroundJobServer();
}

/// <summary>
/// 配置注入
/// </summary>
/// <param name="builder"></param>
/// <param name="configFileName"></param>
/// <returns></returns>
/// <exception cref="FileNotFoundException"></exception>
public static async Task<AppSettingConfig> AddAppConfig(this ContainerBuilder builder, string configFileName = "appsettings.json")
{
var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFileName);

if (!File.Exists(configFile)) throw new FileNotFoundException($"{configFileName} 配置文件不存在");

string jsonString;
using (var stream = File.OpenRead(configFile))
{
var reader = new StreamReader(stream);
jsonString = await reader.ReadToEndAsync();
}

var appSetting = JsonConvert.DeserializeObject<AppSettingConfig>(jsonString);

builder
.RegisterInstance(appSetting)
.SingleInstance();

return appSetting;
}

/// <summary>
/// 服务注入
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
private static ContainerBuilder AddServices(this ContainerBuilder builder)
{
var interfaceType = typeof(IBaseService);

//通过表达式过滤不需要加载的程序集
var types =
AppDomain.CurrentDomain.GetReferanceAssemblies(x => x.FullName.StartsWith("ACD."));

var interfaceTypes = types
.SelectMany(s => s.GetTypes())
.Where(t => interfaceType.IsAssignableFrom(t)
&& t.IsClass && !t.IsAbstract)
.Select(t => new
{
Service = t.GetInterfaces().FirstOrDefault(),
Implementation = t
})
.Where(t => t.Service != null
&& interfaceType.IsAssignableFrom(t.Service));

foreach (var type in interfaceTypes)
{
//这里默认为瞬时注入,可根据传入参数决定注入的生命周期
//或者将IBaseService拆分为三个接口,对应三个不同的生命周期分别注入
builder.RegisterType(type.Implementation)
.As(type.Service)
.InstancePerDependency();
}

return builder;
}
}

ACD.Client项目中AppInit.cs调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
internal class AppInit
{
private static IContainer Container;

internal static IDisposable BackgroundJobServers;

internal static async Task Init()
{
var builder = new ContainerBuilder();

var config = await builder.AddAppConfig("appsettings.json");

BackgroundJobServers = GlobalConfiguration.Configuration.AddHangfireService(config);

builder.AddInfrastructure(config);

Container = builder.Build();
}

internal static T Resolve<T>() => Container.Resolve<T>();
}

使用

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
//C/S端:

await AppInit.Init();

//B/S端:

将AppInit中的内容在Global.asax中或ApplicationStart中实现

//Point为实体类

IDbRepository<Point> pointRepo = AppInit.Resolve<IDbRepository<Point>>();
var results = await pointRepo.GetListAsync();

//or

public class ACDesign
{
private readonly IDbRepository<Point> _pointRepo;

public ACDesign(IDbRepository<Point> pointRepo) => _pointRepo = pointRepo;

public void Demo()
{
// _pointRepo.GetListAsync();
}
}

ACD.Client项目中的配置文件appsettings.json修改如下:

1
2
3
4
5
6
7
8
9
10
11
{
"ACDesignDbConfig": {
"Name": "ACDesign",
"ConnectionString": "Data Source=localhost;Initial Catalog = ACDesign;User Id = sa;Password = 123456;",
"IsAutoCloseConnection": true,
"Default": true,
"DbType": "SqlServer"
},
"HangfireStorage": "Data Source=localhost;Initial Catalog = hangfire;User Id = sa;Password = 123456;"
}


C#基于Autocad的二次开发(9.Sqlsugar仓储模式)
https://wangyuangen.github.io/2024/05/20/CsharpAutocad9/
作者
Yuangen Wang
发布于
2024年5月20日
许可协议