75 lines
2.4 KiB
C#
75 lines
2.4 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.Repositories.Common;
|
|
using MyCode.Project.Infrastructure.Extensions;
|
|
|
|
namespace MyCode.Project.GenerateCode
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
//Console.WriteLine(FileHelper.MapPath("/"));
|
|
|
|
|
|
//要生成的仓储和实体对象,不用整个库全部生成,只生成想要的就行
|
|
var listTalbeName = new List<string>()
|
|
{ "WMStoJackyun_InventoryMovement_View2"};
|
|
|
|
using (var db = new WMSSqlSugarClient())
|
|
{
|
|
var tables = db.DbMaintenance.GetTableInfoList(false);
|
|
|
|
var solutionPath = FileUtils.GetSolutionPath();
|
|
|
|
Console.WriteLine($"当前解决方案所在目录:{solutionPath}");
|
|
|
|
foreach (var item in tables)
|
|
{
|
|
if (!listTalbeName.Exists(p => p == item.Name)) { continue; }
|
|
|
|
string entityName = item.Name.ToHumpName();
|
|
|
|
db.MappingTables.Add(entityName, item.Name);
|
|
|
|
foreach (var col in db.DbMaintenance.GetColumnInfosByTableName(item.Name))
|
|
{
|
|
db.MappingColumns.Add(col.DbColumnName.ToHumpName() /*Format class property name*/, col.DbColumnName, entityName);
|
|
}
|
|
|
|
//生成所有实体
|
|
db.DbFirst.IsCreateAttribute(true).CreateClassFile(Path.Combine(FileUtils.GetSolutionPath(), "MyCode.Project.Domain", "ZHMDModel"), "MyCode.Project.Domain.ZHMDModel", entityName);
|
|
}
|
|
|
|
|
|
foreach (var table in tables)
|
|
{
|
|
if (!listTalbeName.Exists(p => p == table.Name)) { continue; }
|
|
|
|
Console.WriteLine(table.Name);
|
|
|
|
|
|
//创建仓储接口
|
|
var templateForRepositoryInterface = new TemplateForRepositoryInterface(table.Name);
|
|
templateForRepositoryInterface.CreateFile();
|
|
|
|
//创建仓储实现类
|
|
var templateForRepository = new TemplateForRepository(table.Name);
|
|
templateForRepository.CreateFile();
|
|
|
|
}
|
|
|
|
Console.WriteLine("代码生成成功");
|
|
}
|
|
|
|
|
|
Console.ReadKey();
|
|
}
|
|
}
|
|
}
|