1 Framework
ansonzhang edited this page 2019-10-15 10:37:12 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

生成整体框架多层类文件

项目开发后期如果添加了一个表但是需要生成四个层文件比较麻烦我根据SQL sugar相关内容写了一个自动生成的方法。

注意:相关代码是 netcore 3.0分支的

上下文与操作类

Blog.Core.Model/Seed/MyContext.cs

Blog.Core.Model/Seed/FrameSeed.cs(可自定义文件生成路径)

依赖注入上下文

services.AddScoped<Blog.Core.Model.Models.MyContext>();

如何使用

Blog.Core/Controller/DbFirst/DbFirstController.cs

 private readonly MyContext myContext;

 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="myContext"></param>
 public DbFirstController(MyContext myContext)
 {
     this.myContext = myContext;
 }

 /// <summary>
 /// 获取 整体框架 文件
 /// </summary>
 /// <returns></returns>
 [HttpGet]
 public bool GetFrameFiles()
 {
     return FrameSeed.CreateModels(myContext)
         && FrameSeed.CreateIRepositorys(myContext)
         && FrameSeed.CreateIServices(myContext)
         && FrameSeed.CreateRepository(myContext)
         && FrameSeed.CreateServices(myContext)
         ;
 }