diff --git a/Falcon.SugarApi/DatabaseDefinitions/DbSet.cs b/Falcon.SugarApi/DatabaseDefinitions/DbSet.cs
new file mode 100644
index 0000000..90daac1
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/DbSet.cs
@@ -0,0 +1,25 @@
+using SqlSugar;
+
+namespace Falcon.SugarApi.DatabaseDefinitions
+{
+ ///
+ /// 代表一张表
+ ///
+ /// 表定义类型
+ public class DbSet : SimpleClient where T : class, new()
+ {
+ ///
+ /// 通过数据上下文构造一张表
+ ///
+ /// 数据上下文
+ public DbSet(SqlSugarClient context) : base(context) { }
+ ///
+ /// 返回可迭代的
+ ///
+ ///
+ public virtual ISugarQueryable Queryable() {
+ return Context.Queryable();
+ }
+ }
+
+}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/MyConnectionConfig.cs b/Falcon.SugarApi/DatabaseDefinitions/SugarConnectionConfig.cs
similarity index 94%
rename from Falcon.SugarApi/DatabaseDefinitions/MyConnectionConfig.cs
rename to Falcon.SugarApi/DatabaseDefinitions/SugarConnectionConfig.cs
index 3f6a19d..f923d20 100644
--- a/Falcon.SugarApi/DatabaseDefinitions/MyConnectionConfig.cs
+++ b/Falcon.SugarApi/DatabaseDefinitions/SugarConnectionConfig.cs
@@ -15,7 +15,9 @@ namespace Falcon.SugarApi.DatabaseDefinitions
/// 是否使用log
///
public bool Log { get; set; }
-
+ ///
+ /// 实例化SugarDb链接配置
+ ///
public SugarConnectionConfig() {
this.ConfigureExternalServices ??= new ConfigureExternalServices { };
this.ConfigureExternalServices.EntityService += (p, c) => {
diff --git a/Falcon.SugarApi/DatabaseDefinitions/SugarDbTables.cs b/Falcon.SugarApi/DatabaseDefinitions/SugarDbTables.cs
new file mode 100644
index 0000000..fb4775d
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/SugarDbTables.cs
@@ -0,0 +1,35 @@
+using SqlSugar;
+using System;
+using System.Reflection;
+
+namespace Falcon.SugarApi.DatabaseDefinitions
+{
+ ///
+ /// 表示数据库表结构定义
+ ///
+ public abstract class SugarDbTables
+ {
+ ///
+ /// 表使用的数据上下文
+ ///
+ private SugarDbContext DbContext { get; set; }
+
+ ///
+ /// 通过数据上下文构造表集合对象,并实例化所有DbSet实例
+ ///
+ /// 使用的数据上下文
+ /// 是否实例化所有DbSet表对象
+ public SugarDbTables(SugarDbContext dbContext, bool createInstance = true) {
+ this.DbContext = dbContext;
+ if (createInstance) {
+ foreach (PropertyInfo property in this.GetType().GetProperties()) {
+ var ptype = property.PropertyType;
+ if (ptype.IsGenericType() && ptype.GetGenericTypeDefinition() == typeof(DbSet<>) && property.CanWrite) {
+ property.SetValue(this, Activator.CreateInstance(ptype, this.DbContext));
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/Falcon.SugarApi/IServiceCollectionExtend.cs b/Falcon.SugarApi/IServiceCollectionExtend.cs
index 881b003..08307e3 100644
--- a/Falcon.SugarApi/IServiceCollectionExtend.cs
+++ b/Falcon.SugarApi/IServiceCollectionExtend.cs
@@ -14,16 +14,6 @@ namespace Falcon.SugarApi
///
public static class IServiceCollectionExtend
{
- ///
- /// 注册Falcon.Sugar相关api方法和数据库上下文。
- ///
- /// 服务集合
- /// 数据上下文配置节点
- /// 服务集合
- public static IServiceCollection AddSugarApiWithDbContext(this IServiceCollection services, SugarConnectionConfig config) {
- return services.AddSugarApiDbContext(config).AddApiReturnModelProvider();
- }
-
///
/// 注册sugarDbcontext数据上下文
///