├── .gitattributes ├── README.md ├── NetCore-Sugar-Demo ├── appsettings.json ├── appsettings.Development.json ├── Repository │ ├── BlogArticleRepository.cs │ └── BaseRepository.cs ├── Properties │ └── launchSettings.json ├── Program.cs ├── sugar │ ├── BaseDBConfig.cs │ └── DbContext.cs ├── NetCore-Sugar-Demo.csproj ├── Controllers │ └── ValuesController.cs ├── Startup.cs ├── Common │ └── Appsettings.cs ├── Model │ └── BlogArticle.cs └── Seed │ └── DBSeed.cs ├── NetCore-Sugar-Demo.sln └── .gitignore /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetCore-Sugar-Demo 2 | 一个NetCore的数据库操作微小Demo; 3 | 4 | ORM是使用的SqlSugar; 5 | 6 | 支持Seed数据库,支持表的CURD; 7 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/appsettings.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anjoy8/NetCore-Sugar-Demo/HEAD/NetCore-Sugar-Demo/appsettings.json -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Repository/BlogArticleRepository.cs: -------------------------------------------------------------------------------- 1 | using NetCoreSugarDemo.Model; 2 | using NetCoreSugarDemo.Repository.Base; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace NetCore_Sugar_Demo.Repository 10 | { 11 | public class BlogArticleRepository: BaseRepository 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "profiles": { 4 | "NetCore_Sugar_Demo": { 5 | "commandName": "Project", 6 | "launchBrowser": true, 7 | "launchUrl": "api/values", 8 | "applicationUrl": "http://localhost:5000", 9 | "environmentVariables": { 10 | "ASPNETCORE_ENVIRONMENT": "Development" 11 | } 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace NetCore_Sugar_Demo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/sugar/BaseDBConfig.cs: -------------------------------------------------------------------------------- 1 | 2 | using NetCoreSugarDemo.Common; 3 | using Microsoft.Extensions.Configuration; 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | 8 | namespace NetCoreSugarDemo.Repository 9 | { 10 | public class BaseDBConfig 11 | { 12 | static string sqlServerConnection = Appsettings.app(new string[] { "AppSettings", "SqlServer", "SqlServerConnection" });//获取连接字符串 13 | static string pwdFile = @"D:\my-file\dbCountPsw122.txt"; 14 | 15 | public static string ConnectionString = File.Exists(pwdFile) ? File.ReadAllText(pwdFile).Trim() : sqlServerConnection; 16 | 17 | //正常格式是 18 | 19 | //public static string ConnectionString = "server=.;uid=sa;pwd=sa;database=WMBlogDB"; 20 | 21 | //原谅我用配置文件的形式,因为我直接调用的是我的服务器账号和密码,安全起见 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/NetCore-Sugar-Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | NetCore_Sugar_Demo 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Always 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28010.2003 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCore-Sugar-Demo", "NetCore-Sugar-Demo\NetCore-Sugar-Demo.csproj", "{3D3F55B4-FE86-4E8B-8D98-400251965A91}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3D3F55B4-FE86-4E8B-8D98-400251965A91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3D3F55B4-FE86-4E8B-8D98-400251965A91}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3D3F55B4-FE86-4E8B-8D98-400251965A91}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3D3F55B4-FE86-4E8B-8D98-400251965A91}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {0DA39356-1E08-4864-8B68-B826CB99348C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using NetCore_Sugar_Demo.Repository; 7 | using NetCore_Sugar_Demo.Seed; 8 | 9 | namespace NetCore_Sugar_Demo.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class ValuesController : ControllerBase 14 | { 15 | // GET api/values 16 | [HttpGet] 17 | public async Task Get() 18 | { 19 | DBSeed.Seed(); 20 | 21 | BlogArticleRepository blogArticleRepository = new BlogArticleRepository(); 22 | 23 | return await blogArticleRepository.Query(); 24 | } 25 | 26 | // GET api/values/5 27 | [HttpGet("{id}")] 28 | public ActionResult Get(int id) 29 | { 30 | return "value"; 31 | } 32 | 33 | // POST api/values 34 | [HttpPost] 35 | public void Post([FromBody] string value) 36 | { 37 | } 38 | 39 | // PUT api/values/5 40 | [HttpPut("{id}")] 41 | public void Put(int id, [FromBody] string value) 42 | { 43 | } 44 | 45 | // DELETE api/values/5 46 | [HttpDelete("{id}")] 47 | public void Delete(int id) 48 | { 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Logging; 11 | using Microsoft.Extensions.Options; 12 | 13 | namespace NetCore_Sugar_Demo 14 | { 15 | public class Startup 16 | { 17 | public Startup(IConfiguration configuration) 18 | { 19 | Configuration = configuration; 20 | } 21 | 22 | public IConfiguration Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); 28 | } 29 | 30 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 31 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 32 | { 33 | if (env.IsDevelopment()) 34 | { 35 | app.UseDeveloperExceptionPage(); 36 | } 37 | 38 | app.UseMvc(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Common/Appsettings.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Microsoft.Extensions.Configuration.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace NetCoreSugarDemo.Common 8 | { 9 | /// 10 | /// appsettings.json操作类 11 | /// 12 | public class Appsettings 13 | { 14 | static IConfiguration Configuration { get; set; } 15 | static Appsettings() 16 | { 17 | //ReloadOnChange = true 当appsettings.json被修改时重新加载 18 | Configuration = new ConfigurationBuilder() 19 | .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true }) 20 | .Build(); 21 | } 22 | /// 23 | /// 封装要操作的字符 24 | /// 25 | /// 26 | /// 27 | public static string app(params string[] sections) 28 | { 29 | try 30 | { 31 | var val = string.Empty; 32 | for (int i = 0; i < sections.Length; i++) 33 | { 34 | val += sections[i] + ":"; 35 | } 36 | 37 | return Configuration[val.TrimEnd(':')]; 38 | } 39 | catch (Exception) 40 | { 41 | return ""; 42 | } 43 | 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Model/BlogArticle.cs: -------------------------------------------------------------------------------- 1 | using SqlSugar; 2 | using System; 3 | 4 | namespace NetCoreSugarDemo.Model 5 | { 6 | /// 7 | /// 博客文章 8 | /// 12 | /// 主键 13 | /// 14 | /// 这里之所以没用RootEntity,是想保持和之前的数据库一致,主键是bID,不是Id 15 | [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = true)] 16 | public int bID { get; set; } 17 | /// 18 | /// 创建人 19 | /// 20 | [SugarColumn(Length = 60, IsNullable = true)] 21 | public string bsubmitter { get; set; } 22 | 23 | /// 24 | /// 标题blog 25 | /// 26 | [SugarColumn(Length = 256, IsNullable = true)] 27 | public string btitle { get; set; } 28 | 29 | /// 30 | /// 类别 31 | /// 32 | [SugarColumn(Length = int.MaxValue, IsNullable = true)] 33 | public string bcategory { get; set; } 34 | 35 | /// 36 | /// 内容 37 | /// 38 | [SugarColumn(IsNullable = true, ColumnDataType = "text")] 39 | public string bcontent { get; set; } 40 | 41 | /// 42 | /// 访问量 43 | /// 44 | public int btraffic { get; set; } 45 | 46 | /// 47 | /// 评论数量 48 | /// 49 | public int bcommentNum { get; set; } 50 | 51 | /// 52 | /// 修改时间 53 | /// 54 | public DateTime bUpdateTime { get; set; } 55 | 56 | /// 57 | /// 创建时间 58 | /// 59 | public System.DateTime bCreateTime { get; set; } 60 | /// 61 | /// 备注 62 | /// 63 | [SugarColumn(Length = int.MaxValue, IsNullable = true)] 64 | public string bRemark { get; set; } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Seed/DBSeed.cs: -------------------------------------------------------------------------------- 1 | using NetCoreSugarDemo.Model; 2 | using NetCoreSugarDemo.Repository; 3 | using SqlSugar; 4 | using System; 5 | using System.IO; 6 | using System.Threading.Tasks; 7 | 8 | namespace NetCore_Sugar_Demo.Seed 9 | { 10 | public class DBSeed 11 | { 12 | /// 13 | /// 异步添加种子数据 14 | /// 15 | /// 16 | /// 17 | public static void Seed() 18 | { 19 | try 20 | { 21 | DbContext.Init(BaseDBConfig.ConnectionString); 22 | DbContext myContext = new DbContext(); 23 | // 注意!一定要手动先创建要给空的数据库 24 | // 会覆盖,可以设置为true,来备份数据 25 | // 如果生成过了,第二次,就不用再执行一遍了,注释掉该方法即可 26 | myContext.CreateTableByEntity(false, typeof(BlogArticle)); 27 | 28 | 29 | 30 | 31 | #region BlogArticle Guestbook 32 | if (!myContext.Db.Queryable().Any()) 33 | { 34 | int bid = myContext.GetEntityDB().InsertReturnIdentity( 35 | new BlogArticle() 36 | { 37 | bsubmitter = "admins", 38 | btitle = "老张的哲学", 39 | bcategory = "技术博文", 40 | bcontent = "

1,ctrl+alt+delete 去修改密码

2、打开“服务器管理器”,选择“配置”-“本地用户和组”-“用户,右击administrator,选择“属性”,在“常规”选项中勾上“密码永不过期”,点击“应用”和“确定”。

3、在开始菜单中选择“管理工具”-“本地安全策略”,选择“安全策略”-“账户策略”-“密码策略”,编辑“密码最短使用期限”和“密码最长使用期限”,天数设置为0,即永不过期,点击“确定”即可。


", 41 | btraffic = 1, 42 | bcommentNum = 0, 43 | bUpdateTime = DateTime.Now, 44 | bCreateTime = DateTime.Now 45 | }); 46 | } 47 | #endregion 48 | 49 | 50 | 51 | 52 | } 53 | catch (Exception ex) 54 | { 55 | throw new Exception("1、注意要先创建空的数据库\n2、" + ex.Message); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015/2017 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # Visual Studio 2017 auto generated files 34 | Generated\ Files/ 35 | 36 | # MSTest test Results 37 | [Tt]est[Rr]esult*/ 38 | [Bb]uild[Ll]og.* 39 | 40 | # NUNIT 41 | *.VisualState.xml 42 | TestResult.xml 43 | 44 | # Build Results of an ATL Project 45 | [Dd]ebugPS/ 46 | [Rr]eleasePS/ 47 | dlldata.c 48 | 49 | # Benchmark Results 50 | BenchmarkDotNet.Artifacts/ 51 | 52 | # .NET Core 53 | project.lock.json 54 | project.fragment.lock.json 55 | artifacts/ 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_h.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *_wpftmp.csproj 81 | *.log 82 | *.vspscc 83 | *.vssscc 84 | .builds 85 | *.pidb 86 | *.svclog 87 | *.scc 88 | 89 | # Chutzpah Test files 90 | _Chutzpah* 91 | 92 | # Visual C++ cache files 93 | ipch/ 94 | *.aps 95 | *.ncb 96 | *.opendb 97 | *.opensdf 98 | *.sdf 99 | *.cachefile 100 | *.VC.db 101 | *.VC.VC.opendb 102 | 103 | # Visual Studio profiler 104 | *.psess 105 | *.vsp 106 | *.vspx 107 | *.sap 108 | 109 | # Visual Studio Trace Files 110 | *.e2e 111 | 112 | # TFS 2012 Local Workspace 113 | $tf/ 114 | 115 | # Guidance Automation Toolkit 116 | *.gpState 117 | 118 | # ReSharper is a .NET coding add-in 119 | _ReSharper*/ 120 | *.[Rr]e[Ss]harper 121 | *.DotSettings.user 122 | 123 | # JustCode is a .NET coding add-in 124 | .JustCode 125 | 126 | # TeamCity is a build add-in 127 | _TeamCity* 128 | 129 | # DotCover is a Code Coverage Tool 130 | *.dotCover 131 | 132 | # AxoCover is a Code Coverage Tool 133 | .axoCover/* 134 | !.axoCover/settings.json 135 | 136 | # Visual Studio code coverage results 137 | *.coverage 138 | *.coveragexml 139 | 140 | # NCrunch 141 | _NCrunch_* 142 | .*crunch*.local.xml 143 | nCrunchTemp_* 144 | 145 | # MightyMoose 146 | *.mm.* 147 | AutoTest.Net/ 148 | 149 | # Web workbench (sass) 150 | .sass-cache/ 151 | 152 | # Installshield output folder 153 | [Ee]xpress/ 154 | 155 | # DocProject is a documentation generator add-in 156 | DocProject/buildhelp/ 157 | DocProject/Help/*.HxT 158 | DocProject/Help/*.HxC 159 | DocProject/Help/*.hhc 160 | DocProject/Help/*.hhk 161 | DocProject/Help/*.hhp 162 | DocProject/Help/Html2 163 | DocProject/Help/html 164 | 165 | # Click-Once directory 166 | publish/ 167 | 168 | # Publish Web Output 169 | *.[Pp]ublish.xml 170 | *.azurePubxml 171 | # Note: Comment the next line if you want to checkin your web deploy settings, 172 | # but database connection strings (with potential passwords) will be unencrypted 173 | *.pubxml 174 | *.publishproj 175 | 176 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 177 | # checkin your Azure Web App publish settings, but sensitive information contained 178 | # in these scripts will be unencrypted 179 | PublishScripts/ 180 | 181 | # NuGet Packages 182 | *.nupkg 183 | # The packages folder can be ignored because of Package Restore 184 | **/[Pp]ackages/* 185 | # except build/, which is used as an MSBuild target. 186 | !**/[Pp]ackages/build/ 187 | # Uncomment if necessary however generally it will be regenerated when needed 188 | #!**/[Pp]ackages/repositories.config 189 | # NuGet v3's project.json files produces more ignorable files 190 | *.nuget.props 191 | *.nuget.targets 192 | 193 | # Microsoft Azure Build Output 194 | csx/ 195 | *.build.csdef 196 | 197 | # Microsoft Azure Emulator 198 | ecf/ 199 | rcf/ 200 | 201 | # Windows Store app package directories and files 202 | AppPackages/ 203 | BundleArtifacts/ 204 | Package.StoreAssociation.xml 205 | _pkginfo.txt 206 | *.appx 207 | 208 | # Visual Studio cache files 209 | # files ending in .cache can be ignored 210 | *.[Cc]ache 211 | # but keep track of directories ending in .cache 212 | !*.[Cc]ache/ 213 | 214 | # Others 215 | ClientBin/ 216 | ~$* 217 | *~ 218 | *.dbmdl 219 | *.dbproj.schemaview 220 | *.jfm 221 | *.pfx 222 | *.publishsettings 223 | orleans.codegen.cs 224 | 225 | # Including strong name files can present a security risk 226 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 227 | #*.snk 228 | 229 | # Since there are multiple workflows, uncomment next line to ignore bower_components 230 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 231 | #bower_components/ 232 | 233 | # RIA/Silverlight projects 234 | Generated_Code/ 235 | 236 | # Backup & report files from converting an old project file 237 | # to a newer Visual Studio version. Backup files are not needed, 238 | # because we have git ;-) 239 | _UpgradeReport_Files/ 240 | Backup*/ 241 | UpgradeLog*.XML 242 | UpgradeLog*.htm 243 | ServiceFabricBackup/ 244 | *.rptproj.bak 245 | 246 | # SQL Server files 247 | *.mdf 248 | *.ldf 249 | *.ndf 250 | 251 | # Business Intelligence projects 252 | *.rdl.data 253 | *.bim.layout 254 | *.bim_*.settings 255 | *.rptproj.rsuser 256 | 257 | # Microsoft Fakes 258 | FakesAssemblies/ 259 | 260 | # GhostDoc plugin setting file 261 | *.GhostDoc.xml 262 | 263 | # Node.js Tools for Visual Studio 264 | .ntvs_analysis.dat 265 | node_modules/ 266 | 267 | # Visual Studio 6 build log 268 | *.plg 269 | 270 | # Visual Studio 6 workspace options file 271 | *.opt 272 | 273 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 274 | *.vbw 275 | 276 | # Visual Studio LightSwitch build output 277 | **/*.HTMLClient/GeneratedArtifacts 278 | **/*.DesktopClient/GeneratedArtifacts 279 | **/*.DesktopClient/ModelManifest.xml 280 | **/*.Server/GeneratedArtifacts 281 | **/*.Server/ModelManifest.xml 282 | _Pvt_Extensions 283 | 284 | # Paket dependency manager 285 | .paket/paket.exe 286 | paket-files/ 287 | 288 | # FAKE - F# Make 289 | .fake/ 290 | 291 | # JetBrains Rider 292 | .idea/ 293 | *.sln.iml 294 | 295 | # CodeRush personal settings 296 | .cr/personal 297 | 298 | # Python Tools for Visual Studio (PTVS) 299 | __pycache__/ 300 | *.pyc 301 | 302 | # Cake - Uncomment if you are using it 303 | # tools/** 304 | # !tools/packages.config 305 | 306 | # Tabs Studio 307 | *.tss 308 | 309 | # Telerik's JustMock configuration file 310 | *.jmconfig 311 | 312 | # BizTalk build output 313 | *.btp.cs 314 | *.btm.cs 315 | *.odx.cs 316 | *.xsd.cs 317 | 318 | # OpenCover UI analysis results 319 | OpenCover/ 320 | 321 | # Azure Stream Analytics local run output 322 | ASALocalRun/ 323 | 324 | # MSBuild Binary and Structured Log 325 | *.binlog 326 | 327 | # NVidia Nsight GPU debugger configuration file 328 | *.nvuser 329 | 330 | # MFractors (Xamarin productivity tool) working folder 331 | .mfractor/ 332 | 333 | # Local History for Visual Studio 334 | .localhistory/ 335 | 336 | # wwwroot/images 337 | *images/ -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/Repository/BaseRepository.cs: -------------------------------------------------------------------------------- 1 | using NetCoreSugarDemo.Model; 2 | using SqlSugar; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq.Expressions; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace NetCoreSugarDemo.Repository.Base 10 | { 11 | public class BaseRepository where TEntity : class, new() 12 | { 13 | private DbContext context; 14 | private SqlSugarClient db; 15 | private SimpleClient entityDB; 16 | 17 | public DbContext Context 18 | { 19 | get { return context; } 20 | set { context = value; } 21 | } 22 | internal SqlSugarClient Db 23 | { 24 | get { return db; } 25 | private set { db = value; } 26 | } 27 | internal SimpleClient EntityDB 28 | { 29 | get { return entityDB; } 30 | private set { entityDB = value; } 31 | } 32 | public BaseRepository() 33 | { 34 | DbContext.Init(BaseDBConfig.ConnectionString); 35 | context = DbContext.GetDbContext(); 36 | db = context.Db; 37 | entityDB = context.GetEntityDB(db); 38 | } 39 | 40 | 41 | 42 | public async Task QueryByID(object objId) 43 | { 44 | return await Task.Run(() => db.Queryable().InSingle(objId)); 45 | } 46 | /// 47 | /// 功能描述:根据ID查询一条数据 48 | /// 作  者:NetCoreSugarDemo 49 | /// 50 | /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 51 | /// 是否使用缓存 52 | /// 数据实体 53 | public async Task QueryByID(object objId, bool blnUseCache = false) 54 | { 55 | return await Task.Run(() => db.Queryable().WithCacheIF(blnUseCache).InSingle(objId)); 56 | } 57 | 58 | /// 59 | /// 功能描述:根据ID查询数据 60 | /// 作  者:NetCoreSugarDemo 61 | /// 62 | /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 63 | /// 数据实体列表 64 | public async Task> QueryByIDs(object[] lstIds) 65 | { 66 | return await Task.Run(() => db.Queryable().In(lstIds).ToList()); 67 | } 68 | 69 | /// 70 | /// 写入实体数据 71 | /// 72 | /// 博文实体类 73 | /// 74 | public async Task Add(TEntity entity) 75 | { 76 | var i = await Task.Run(() => db.Insertable(entity).ExecuteReturnBigIdentity()); 77 | //返回的i是long类型,这里你可以根据你的业务需要进行处理 78 | return (int)i; 79 | } 80 | 81 | /// 82 | /// 更新实体数据 83 | /// 84 | /// 博文实体类 85 | /// 86 | public async Task Update(TEntity entity) 87 | { 88 | //这种方式会以主键为条件 89 | var i = await Task.Run(() => db.Updateable(entity).ExecuteCommand()); 90 | return i > 0; 91 | } 92 | 93 | public async Task Update(TEntity entity, string strWhere) 94 | { 95 | return await Task.Run(() => db.Updateable(entity).Where(strWhere).ExecuteCommand() > 0); 96 | } 97 | 98 | public async Task Update(string strSql, SugarParameter[] parameters = null) 99 | { 100 | return await Task.Run(() => db.Ado.ExecuteCommand(strSql, parameters) > 0); 101 | } 102 | 103 | public async Task Update( 104 | TEntity entity, 105 | List lstColumns = null, 106 | List lstIgnoreColumns = null, 107 | string strWhere = "" 108 | ) 109 | { 110 | IUpdateable up = await Task.Run(() => db.Updateable(entity)); 111 | if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0) 112 | { 113 | up = await Task.Run(() => up.IgnoreColumns(it => lstIgnoreColumns.Contains(it))); 114 | } 115 | if (lstColumns != null && lstColumns.Count > 0) 116 | { 117 | up = await Task.Run(() => up.UpdateColumns(it => lstColumns.Contains(it))); 118 | } 119 | if (!string.IsNullOrEmpty(strWhere)) 120 | { 121 | up = await Task.Run(() => up.Where(strWhere)); 122 | } 123 | return await Task.Run(() => up.ExecuteCommand()) > 0; 124 | } 125 | 126 | /// 127 | /// 根据实体删除一条数据 128 | /// 129 | /// 博文实体类 130 | /// 131 | public async Task Delete(TEntity entity) 132 | { 133 | var i = await Task.Run(() => db.Deleteable(entity).ExecuteCommand()); 134 | return i > 0; 135 | } 136 | 137 | /// 138 | /// 删除指定ID的数据 139 | /// 140 | /// 主键ID 141 | /// 142 | public async Task DeleteById(object id) 143 | { 144 | var i = await Task.Run(() => db.Deleteable(id).ExecuteCommand()); 145 | return i > 0; 146 | } 147 | 148 | /// 149 | /// 删除指定ID集合的数据(批量删除) 150 | /// 151 | /// 主键ID集合 152 | /// 153 | public async Task DeleteByIds(object[] ids) 154 | { 155 | var i = await Task.Run(() => db.Deleteable().In(ids).ExecuteCommand()); 156 | return i > 0; 157 | } 158 | 159 | 160 | 161 | /// 162 | /// 功能描述:查询所有数据 163 | /// 作  者:NetCoreSugarDemo 164 | /// 165 | /// 数据列表 166 | public async Task> Query() 167 | { 168 | return await Task.Run(() => entityDB.GetList()); 169 | } 170 | 171 | /// 172 | /// 功能描述:查询数据列表 173 | /// 作  者:NetCoreSugarDemo 174 | /// 175 | /// 条件 176 | /// 数据列表 177 | public async Task> Query(string strWhere) 178 | { 179 | return await Task.Run(() => db.Queryable().WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList()); 180 | } 181 | 182 | /// 183 | /// 功能描述:查询数据列表 184 | /// 作  者:NetCoreSugarDemo 185 | /// 186 | /// whereExpression 187 | /// 数据列表 188 | public async Task> Query(Expression> whereExpression) 189 | { 190 | return await Task.Run(() => entityDB.GetList(whereExpression)); 191 | } 192 | 193 | /// 194 | /// 功能描述:查询一个列表 195 | /// 作  者:NetCoreSugarDemo 196 | /// 197 | /// 条件表达式 198 | /// 排序字段,如name asc,age desc 199 | /// 数据列表 200 | public async Task> Query(Expression> whereExpression, string strOrderByFileds) 201 | { 202 | return await Task.Run(() => db.Queryable().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToList()); 203 | } 204 | /// 205 | /// 功能描述:查询一个列表 206 | /// 207 | /// 208 | /// 209 | /// 210 | /// 211 | public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true) 212 | { 213 | return await Task.Run(() => db.Queryable().OrderByIF(orderByExpression != null, orderByExpression, isAsc ? OrderByType.Asc : OrderByType.Desc).WhereIF(whereExpression != null, whereExpression).ToList()); 214 | } 215 | 216 | /// 217 | /// 功能描述:查询一个列表 218 | /// 作  者:NetCoreSugarDemo 219 | /// 220 | /// 条件 221 | /// 排序字段,如name asc,age desc 222 | /// 数据列表 223 | public async Task> Query(string strWhere, string strOrderByFileds) 224 | { 225 | return await Task.Run(() => db.Queryable().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToList()); 226 | } 227 | 228 | 229 | /// 230 | /// 功能描述:查询前N条数据 231 | /// 作  者:NetCoreSugarDemo 232 | /// 233 | /// 条件表达式 234 | /// 前N条 235 | /// 排序字段,如name asc,age desc 236 | /// 数据列表 237 | public async Task> Query( 238 | Expression> whereExpression, 239 | int intTop, 240 | string strOrderByFileds) 241 | { 242 | return await Task.Run(() => db.Queryable().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).Take(intTop).ToList()); 243 | } 244 | 245 | /// 246 | /// 功能描述:查询前N条数据 247 | /// 作  者:NetCoreSugarDemo 248 | /// 249 | /// 条件 250 | /// 前N条 251 | /// 排序字段,如name asc,age desc 252 | /// 数据列表 253 | public async Task> Query( 254 | string strWhere, 255 | int intTop, 256 | string strOrderByFileds) 257 | { 258 | return await Task.Run(() => db.Queryable().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).Take(intTop).ToList()); 259 | } 260 | 261 | 262 | 263 | /// 264 | /// 功能描述:分页查询 265 | /// 作  者:NetCoreSugarDemo 266 | /// 267 | /// 条件表达式 268 | /// 页码(下标0) 269 | /// 页大小 270 | /// 数据总量 271 | /// 排序字段,如name asc,age desc 272 | /// 数据列表 273 | public async Task> Query( 274 | Expression> whereExpression, 275 | int intPageIndex, 276 | int intPageSize, 277 | string strOrderByFileds) 278 | { 279 | return await Task.Run(() => db.Queryable().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(whereExpression != null, whereExpression).ToPageList(intPageIndex, intPageSize)); 280 | } 281 | 282 | /// 283 | /// 功能描述:分页查询 284 | /// 作  者:NetCoreSugarDemo 285 | /// 286 | /// 条件 287 | /// 页码(下标0) 288 | /// 页大小 289 | /// 数据总量 290 | /// 排序字段,如name asc,age desc 291 | /// 数据列表 292 | public async Task> Query( 293 | string strWhere, 294 | int intPageIndex, 295 | int intPageSize, 296 | 297 | string strOrderByFileds) 298 | { 299 | return await Task.Run(() => db.Queryable().OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds).WhereIF(!string.IsNullOrEmpty(strWhere), strWhere).ToPageList(intPageIndex, intPageSize)); 300 | } 301 | 302 | 303 | 304 | 305 | public async Task> QueryPage(Expression> whereExpression, 306 | int intPageIndex = 0, int intPageSize = 20, string strOrderByFileds = null) 307 | { 308 | return await Task.Run(() => db.Queryable() 309 | .OrderByIF(!string.IsNullOrEmpty(strOrderByFileds), strOrderByFileds) 310 | .WhereIF(whereExpression != null, whereExpression) 311 | .ToPageList(intPageIndex, intPageSize)); 312 | } 313 | 314 | 315 | 316 | 317 | } 318 | 319 | 320 | } 321 | -------------------------------------------------------------------------------- /NetCore-Sugar-Demo/sugar/DbContext.cs: -------------------------------------------------------------------------------- 1 | using SqlSugar; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace NetCoreSugarDemo.Repository 7 | { 8 | public class DbContext 9 | { 10 | 11 | private static string _connectionString; 12 | private static DbType _dbType; 13 | private SqlSugarClient _db; 14 | 15 | /// 16 | /// 连接字符串 17 | /// NetCoreSugarDemo 18 | /// 19 | public static string ConnectionString 20 | { 21 | get { return _connectionString; } 22 | set { _connectionString = value; } 23 | } 24 | /// 25 | /// 数据库类型 26 | /// NetCoreSugarDemo 27 | /// 28 | public static DbType DbType 29 | { 30 | get { return _dbType; } 31 | set { _dbType = value; } 32 | } 33 | /// 34 | /// 数据连接对象 35 | /// NetCoreSugarDemo 36 | /// 37 | public SqlSugarClient Db 38 | { 39 | get { return _db; } 40 | private set { _db = value; } 41 | } 42 | 43 | /// 44 | /// 数据库上下文实例(自动关闭连接) 45 | /// NetCoreSugarDemo 46 | /// 47 | public static DbContext Context 48 | { 49 | get 50 | { 51 | return new DbContext(); 52 | } 53 | 54 | } 55 | 56 | 57 | /// 58 | /// 功能描述:构造函数 59 | /// 作  者:NetCoreSugarDemo 60 | /// 61 | public DbContext() 62 | { 63 | if (string.IsNullOrEmpty(_connectionString)) 64 | throw new ArgumentNullException("数据库连接字符串为空"); 65 | _db = new SqlSugarClient(new ConnectionConfig() 66 | { 67 | ConnectionString = _connectionString, 68 | DbType = DbType.SqlServer, 69 | IsAutoCloseConnection = true, 70 | IsShardSameThread = false, 71 | InitKeyType = InitKeyType.Attribute,//mark 72 | ConfigureExternalServices = new ConfigureExternalServices() 73 | { 74 | //DataInfoCacheService = new HttpRuntimeCache() 75 | }, 76 | MoreSettings = new ConnMoreSettings() 77 | { 78 | //IsWithNoLockQuery = true, 79 | IsAutoRemoveDataCache = true 80 | } 81 | }); 82 | } 83 | 84 | /// 85 | /// 功能描述:构造函数 86 | /// 作  者:NetCoreSugarDemo 87 | /// 88 | /// 是否自动关闭连接 89 | private DbContext(bool blnIsAutoCloseConnection) 90 | { 91 | if (string.IsNullOrEmpty(_connectionString)) 92 | throw new ArgumentNullException("数据库连接字符串为空"); 93 | _db = new SqlSugarClient(new ConnectionConfig() 94 | { 95 | ConnectionString = _connectionString, 96 | DbType = _dbType, 97 | IsAutoCloseConnection = blnIsAutoCloseConnection, 98 | IsShardSameThread = true, 99 | ConfigureExternalServices = new ConfigureExternalServices() 100 | { 101 | //DataInfoCacheService = new HttpRuntimeCache() 102 | }, 103 | MoreSettings = new ConnMoreSettings() 104 | { 105 | //IsWithNoLockQuery = true, 106 | IsAutoRemoveDataCache = true 107 | } 108 | }); 109 | } 110 | 111 | #region 实例方法 112 | /// 113 | /// 功能描述:获取数据库处理对象 114 | /// 作  者:NetCoreSugarDemo 115 | /// 116 | /// 返回值 117 | public SimpleClient GetEntityDB() where T : class, new() 118 | { 119 | return new SimpleClient(_db); 120 | } 121 | /// 122 | /// 功能描述:获取数据库处理对象 123 | /// 作  者:NetCoreSugarDemo 124 | /// 125 | /// db 126 | /// 返回值 127 | public SimpleClient GetEntityDB(SqlSugarClient db) where T : class, new() 128 | { 129 | return new SimpleClient(db); 130 | } 131 | 132 | #region 根据数据库表生产实体类 133 | /// 134 | /// 功能描述:根据数据库表生产实体类 135 | /// 作  者:NetCoreSugarDemo 136 | /// 137 | /// 实体类存放路径 138 | public void CreateClassFileByDBTalbe(string strPath) 139 | { 140 | CreateClassFileByDBTalbe(strPath, "NetCoreSugarDemo.Entity"); 141 | } 142 | /// 143 | /// 功能描述:根据数据库表生产实体类 144 | /// 作  者:NetCoreSugarDemo 145 | /// 146 | /// 实体类存放路径 147 | /// 命名空间 148 | public void CreateClassFileByDBTalbe(string strPath, string strNameSpace) 149 | { 150 | CreateClassFileByDBTalbe(strPath, strNameSpace, null); 151 | } 152 | 153 | /// 154 | /// 功能描述:根据数据库表生产实体类 155 | /// 作  者:NetCoreSugarDemo 156 | /// 157 | /// 实体类存放路径 158 | /// 命名空间 159 | /// 生产指定的表 160 | public void CreateClassFileByDBTalbe( 161 | string strPath, 162 | string strNameSpace, 163 | string[] lstTableNames) 164 | { 165 | CreateClassFileByDBTalbe(strPath, strNameSpace, lstTableNames, string.Empty); 166 | } 167 | 168 | /// 169 | /// 功能描述:根据数据库表生产实体类 170 | /// 作  者:NetCoreSugarDemo 171 | /// 172 | /// 实体类存放路径 173 | /// 命名空间 174 | /// 生产指定的表 175 | /// 实现接口 176 | public void CreateClassFileByDBTalbe( 177 | string strPath, 178 | string strNameSpace, 179 | string[] lstTableNames, 180 | string strInterface, 181 | bool blnSerializable = false) 182 | { 183 | if (lstTableNames != null && lstTableNames.Length > 0) 184 | { 185 | _db.DbFirst.Where(lstTableNames).IsCreateDefaultValue().IsCreateAttribute() 186 | .SettingClassTemplate(p => p = @" 187 | {using} 188 | 189 | namespace {Namespace} 190 | { 191 | {ClassDescription}{SugarTable}" + (blnSerializable ? "[Serializable]" : "") + @" 192 | public partial class {ClassName}" + (string.IsNullOrEmpty(strInterface) ? "" : (" : " + strInterface)) + @" 193 | { 194 | public {ClassName}() 195 | { 196 | {Constructor} 197 | } 198 | {PropertyName} 199 | } 200 | } 201 | ") 202 | .SettingPropertyTemplate(p => p = @" 203 | {SugarColumn} 204 | public {PropertyType} {PropertyName} 205 | { 206 | get 207 | { 208 | return _{PropertyName}; 209 | } 210 | set 211 | { 212 | if(_{PropertyName}!=value) 213 | { 214 | base.SetValueCall(" + "\"{PropertyName}\",_{PropertyName}" + @"); 215 | } 216 | _{PropertyName}=value; 217 | } 218 | }") 219 | .SettingPropertyDescriptionTemplate(p => p = " private {PropertyType} _{PropertyName};\r\n" + p) 220 | .SettingConstructorTemplate(p => p = " this._{PropertyName} ={DefaultValue};") 221 | .CreateClassFile(strPath, strNameSpace); 222 | } 223 | else 224 | { 225 | _db.DbFirst.IsCreateAttribute().IsCreateDefaultValue() 226 | .SettingClassTemplate(p => p = @" 227 | {using} 228 | 229 | namespace {Namespace} 230 | { 231 | {ClassDescription}{SugarTable}" + (blnSerializable ? "[Serializable]" : "") + @" 232 | public partial class {ClassName}" + (string.IsNullOrEmpty(strInterface) ? "" : (" : " + strInterface)) + @" 233 | { 234 | public {ClassName}() 235 | { 236 | {Constructor} 237 | } 238 | {PropertyName} 239 | } 240 | } 241 | ") 242 | .SettingPropertyTemplate(p => p = @" 243 | {SugarColumn} 244 | public {PropertyType} {PropertyName} 245 | { 246 | get 247 | { 248 | return _{PropertyName}; 249 | } 250 | set 251 | { 252 | if(_{PropertyName}!=value) 253 | { 254 | base.SetValueCall(" + "\"{PropertyName}\",_{PropertyName}" + @"); 255 | } 256 | _{PropertyName}=value; 257 | } 258 | }") 259 | .SettingPropertyDescriptionTemplate(p => p = " private {PropertyType} _{PropertyName};\r\n" + p) 260 | .SettingConstructorTemplate(p => p = " this._{PropertyName} ={DefaultValue};") 261 | .CreateClassFile(strPath, strNameSpace); 262 | } 263 | } 264 | #endregion 265 | 266 | #region 根据实体类生成数据库表 267 | /// 268 | /// 功能描述:根据实体类生成数据库表 269 | /// 作  者:NetCoreSugarDemo 270 | /// 271 | /// 是否备份表 272 | /// 指定的实体 273 | public void CreateTableByEntity(bool blnBackupTable, params T[] lstEntitys) where T : class, new() 274 | { 275 | Type[] lstTypes = null; 276 | if (lstEntitys != null) 277 | { 278 | lstTypes = new Type[lstEntitys.Length]; 279 | for (int i = 0; i < lstEntitys.Length; i++) 280 | { 281 | T t = lstEntitys[i]; 282 | lstTypes[i] = typeof(T); 283 | } 284 | } 285 | CreateTableByEntity(blnBackupTable, lstTypes); 286 | } 287 | 288 | /// 289 | /// 功能描述:根据实体类生成数据库表 290 | /// 作  者:NetCoreSugarDemo 291 | /// 292 | /// 是否备份表 293 | /// 指定的实体 294 | public void CreateTableByEntity(bool blnBackupTable, params Type[] lstEntitys) 295 | { 296 | if (blnBackupTable) 297 | { 298 | _db.CodeFirst.BackupTable().InitTables(lstEntitys); //change entity backupTable 299 | } 300 | else 301 | { 302 | _db.CodeFirst.InitTables(lstEntitys); 303 | } 304 | } 305 | #endregion 306 | 307 | #endregion 308 | 309 | #region 静态方法 310 | 311 | /// 312 | /// 功能描述:获得一个DbContext 313 | /// 作  者:NetCoreSugarDemo 314 | /// 315 | /// 是否自动关闭连接(如果为false,则使用接受时需要手动关闭Db) 316 | /// 返回值 317 | public static DbContext GetDbContext(bool blnIsAutoCloseConnection = true) 318 | { 319 | return new DbContext(blnIsAutoCloseConnection); 320 | } 321 | 322 | /// 323 | /// 功能描述:设置初始化参数 324 | /// 作  者:NetCoreSugarDemo 325 | /// 326 | /// 连接字符串 327 | /// 数据库类型 328 | public static void Init(string strConnectionString, DbType enmDbType = SqlSugar.DbType.SqlServer) 329 | { 330 | _connectionString = strConnectionString; 331 | _dbType = enmDbType; 332 | } 333 | 334 | /// 335 | /// 功能描述:创建一个链接配置 336 | /// 作  者:NetCoreSugarDemo 337 | /// 338 | /// 是否自动关闭连接 339 | /// 是否夸类事务 340 | /// ConnectionConfig 341 | public static ConnectionConfig GetConnectionConfig(bool blnIsAutoCloseConnection = true, bool blnIsShardSameThread = false) 342 | { 343 | ConnectionConfig config = new ConnectionConfig() 344 | { 345 | ConnectionString = _connectionString, 346 | DbType = _dbType, 347 | IsAutoCloseConnection = blnIsAutoCloseConnection, 348 | ConfigureExternalServices = new ConfigureExternalServices() 349 | { 350 | //DataInfoCacheService = new HttpRuntimeCache() 351 | }, 352 | IsShardSameThread = blnIsShardSameThread 353 | }; 354 | return config; 355 | } 356 | 357 | /// 358 | /// 功能描述:获取一个自定义的DB 359 | /// 作  者:NetCoreSugarDemo 360 | /// 361 | /// config 362 | /// 返回值 363 | public static SqlSugarClient GetCustomDB(ConnectionConfig config) 364 | { 365 | return new SqlSugarClient(config); 366 | } 367 | /// 368 | /// 功能描述:获取一个自定义的数据库处理对象 369 | /// 作  者:NetCoreSugarDemo 370 | /// 371 | /// sugarClient 372 | /// 返回值 373 | public static SimpleClient GetCustomEntityDB(SqlSugarClient sugarClient) where T : class, new() 374 | { 375 | return new SimpleClient(sugarClient); 376 | } 377 | /// 378 | /// 功能描述:获取一个自定义的数据库处理对象 379 | /// 作  者:NetCoreSugarDemo 380 | /// 381 | /// config 382 | /// 返回值 383 | public static SimpleClient GetCustomEntityDB(ConnectionConfig config) where T : class, new() 384 | { 385 | SqlSugarClient sugarClient = GetCustomDB(config); 386 | return GetCustomEntityDB(sugarClient); 387 | } 388 | #endregion 389 | } 390 | } 391 | --------------------------------------------------------------------------------