shgx_tz_mom/ZR.Repository/System/CodeGeneratorRepository.cs

46 lines
1.5 KiB
C#
Raw Normal View History

2021-09-06 18:35:36 +08:00
using Infrastructure.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZR.Model;
using ZR.Model.CodeGenerator;
namespace ZR.Repository.System
{
[AppService(ServiceLifetime = LifeTime.Transient)]
2021-09-06 21:37:32 +08:00
public class CodeGeneratorRepository : BaseRepository
2021-09-06 18:35:36 +08:00
{
/// <summary>
/// 获取数据库信息
/// </summary>
/// <returns></returns>
public List<DataBaseInfo> GetAllDataBaseInfos()
{
return Db.Ado.SqlQuery<DataBaseInfo>("select name as DbName from master..sysdatabases ");
}
/// <summary>
/// 获取所有的表
/// </summary>
2021-09-06 21:37:32 +08:00
/// <param name="dbName"></param>
/// <param name="pager"></param>
/// <param name="tableName"></param>
2021-09-06 18:35:36 +08:00
/// <returns></returns>
2021-09-06 21:37:32 +08:00
public List<DbTableInfo> GetAllTables(string dbName, string tableName, PagerInfo pager)
2021-09-06 18:35:36 +08:00
{
2021-09-06 21:37:32 +08:00
string sql = $"SELECT name as TableName FROM {dbName}..SysObjects Where XType='U'";
int total = 0;
var list = Db.SqlQueryable<DbTableInfo>(sql)
//.WithCache(60 * 10)
.WhereIF(!string.IsNullOrEmpty(tableName), it => it.TableName.Contains(tableName))
.AddParameters(new { dbName })
.OrderBy(x => x.TableName)
.ToPageList(pager.PageNum, pager.PageSize, ref total);
pager.TotalNum = total;
return list;
2021-09-06 18:35:36 +08:00
}
}
}