64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using MyCode.Project.Generate.Template;
|
|||
|
using MyCode.Project.Infrastructure.Common;
|
|||
|
using MyCode.Project.Repositories.Common;
|
|||
|
|
|||
|
namespace MyCode.Project.GenerateCode
|
|||
|
{
|
|||
|
class Program
|
|||
|
{
|
|||
|
static void Main(string[] args)
|
|||
|
{
|
|||
|
//Console.WriteLine(FileHelper.MapPath("/"));
|
|||
|
|
|||
|
//要生成的仓储和实体对象,不用整个库全部生成,只生成想要的就行
|
|||
|
var listTalbeName = new List<string>()
|
|||
|
{ "T_BD_StaffData","T_BD_StaffData_L","SysWorkProcessV2","BasDepartment","T_BAS_SYSPARAMETER","BasEmployee","BasEmployeeDepart","T_BD_DEPARTMENT_L","RpEmployeeDepartLog"};
|
|||
|
|
|||
|
|
|||
|
using (var db = new MyCodeSqlSugarClient())
|
|||
|
{
|
|||
|
db.DbMaintenance.SetListTalbeName(listTalbeName);
|
|||
|
var tables = db.DbMaintenance.GetTableInfoList();
|
|||
|
|
|||
|
var solutionPath = FileUtils.GetSolutionPath();
|
|||
|
|
|||
|
Console.WriteLine($"当前解决方案所在目录:{solutionPath}");
|
|||
|
|
|||
|
int i = 1;
|
|||
|
foreach (var table in tables)
|
|||
|
{
|
|||
|
if (!listTalbeName.Exists(p => p == table.Name)) {
|
|||
|
Console.WriteLine((i++) +$"跳过表:{table.Name}");
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
Console.WriteLine(table.Name);
|
|||
|
|
|||
|
//创建仓储接口
|
|||
|
var templateForRepositoryInterface = new TemplateForRepositoryInterface(table.Name);
|
|||
|
templateForRepositoryInterface.CreateFile();
|
|||
|
|
|||
|
//创建仓储实现类
|
|||
|
var templateForRepository = new TemplateForRepository(table.Name);
|
|||
|
templateForRepository.CreateFile();
|
|||
|
|
|||
|
////生成所有实体
|
|||
|
db.DbFirst.IsCreateAttribute(true)
|
|||
|
.CreateClassFile(Path.Combine(FileUtils.GetSolutionPath(), "MyCode.Project.Domain", "Model"), "MyCode.Project.Domain.Model", table.Name);
|
|||
|
}
|
|||
|
|
|||
|
Console.WriteLine("代码生成成功");
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
Console.ReadKey();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|