using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OrmTest { public class UCustom015 { public static void Init() { var db = NewUnitTest.Db; db.DbMaintenance.CreateDatabase(); db.CodeFirst.InitTables(); db.CodeFirst.InitTables(); db.CodeFirst.InitTables(); db.DbMaintenance.TruncateTable("Country_1111"); db.DbMaintenance.TruncateTable("Province_1111"); db.DbMaintenance.TruncateTable("Country111Info"); var c = new Country1111() { Id=1, Name="中国",InfoId=1 }; var ps = new List(){ new Province1111{ Id=1001, Name="江苏", CountryId=1 }, new Province1111{ Id=1002, Name="上海", CountryId=1 }, new Province1111{ Id=1003, Name="北京", CountryId=1 } }; db.Insertable(c).ExecuteCommand(); db.Insertable(ps).ExecuteCommand(); db.Insertable(new Country111Info { Id=1, Name="infoa"}).ExecuteCommand(); db.Aop.OnLogExecuted = (sq, p) => { Console.WriteLine(sq); }; var list = db.Queryable() .Includes(x => x.Info) .ToList(); var list2 = db.Queryable() .Includes(x => x.Provinces.OrderByDescending(x111 => x111.Id).ToList()) .ToList(); db.CodeFirst.InitTables(); db.DbMaintenance.TruncateTable(); db.Insertable(new SysTimer() { CreatedTime=DateTime.Now, CreatedUserId=1, CreatedUserName=DateTime.Now.ToString(), Cron="", DoOnce=1, Headers="", ExecuteType=1, Interval=1, IsDeleted=1, RequestParameters="", StartNow=1, JobName="a", Remark="a", RequestType=1, RequestUrl="a", TimerType=1, UpdatedTime=DateTime.Now, UpdatedUserId=1, UpdatedUserName="admin" }).ExecuteCommand(); var list3=db.Queryable().Select().ToList(); } /// /// 本地任务信息 /// public class LocalJobOutput { /// /// 任务名称 /// public string JobName { get; set; } /// /// 只执行一次 /// public bool DoOnce { get; set; } = false; /// /// 立即执行(默认等待启动) /// public bool StartNow { get; set; } = false; /// /// 执行间隔时间(单位秒) /// public int Interval { get; set; } /// /// Cron表达式 /// public string Cron { get; set; } /// /// 请求url /// public string RequestUrl { get; set; } /// /// 备注 /// public string Remark { get; set; } } /// /// 定时任务表 /// [SugarTable("sys_timer")] public class SysTimer { /// /// Id主键 /// [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)] public long Id { get; set; } /// /// 任务名称 /// [SugarColumn(ColumnName = "JobName")] public string JobName { get; set; } /// /// 只执行一次 /// [SugarColumn(ColumnName = "DoOnce")] public byte DoOnce { get; set; } /// /// 立即执行 /// [SugarColumn(ColumnName = "StartNow")] public byte StartNow { get; set; } /// /// 执行类型 /// [SugarColumn(ColumnName = "ExecuteType")] public int ExecuteType { get; set; } /// /// 间隔时间 /// 默认值: NULL /// public int? Interval { get; set; } /// /// Cron表达式 /// 默认值: NULL /// [SugarColumn(ColumnName = "Cron")] public string Cron { get; set; } /// /// 定时器类型 /// [SugarColumn(ColumnName = "TimerType")] public int TimerType { get; set; } /// /// 请求url /// 默认值: NULL /// [SugarColumn(ColumnName = "RequestUrl")] public string RequestUrl { get; set; } /// /// 请求参数 /// 默认值: NULL /// [SugarColumn(ColumnName = "RequestParameters")] public string RequestParameters { get; set; } /// /// Headers /// 默认值: NULL /// [SugarColumn(ColumnName = "Headers")] public string Headers { get; set; } /// /// 请求类型 /// [SugarColumn(ColumnName = "RequestType")] public int RequestType { get; set; } /// /// 备注 /// 默认值: NULL /// [SugarColumn(ColumnName = "Remark")] public string Remark { get; set; } /// /// 创建时间 /// 默认值: NULL /// [SugarColumn(ColumnName = "CreatedTime")] public DateTime? CreatedTime { get; set; } /// /// 更新时间 /// 默认值: NULL /// [SugarColumn(ColumnName = "UpdatedTime")] public DateTime? UpdatedTime { get; set; } /// /// 创建者Id /// 默认值: NULL /// [SugarColumn(ColumnName = "CreatedUserId")] public long? CreatedUserId { get; set; } /// /// 创建者名称 /// 默认值: NULL /// [SugarColumn(ColumnName = "CreatedUserName")] public string CreatedUserName { get; set; } /// /// 修改者Id /// 默认值: NULL /// [SugarColumn(ColumnName = "UpdatedUserId")] public long? UpdatedUserId { get; set; } /// /// 修改者名称 /// 默认值: NULL /// [SugarColumn(ColumnName = "UpdatedUserName")] public string UpdatedUserName { get; set; } /// /// 软删除标记 /// [SugarColumn(ColumnName = "IsDeleted")] public byte IsDeleted { get; set; } } [SugarTable("Country_1111")] public class Country1111 { [SqlSugar.SugarColumn(IsPrimaryKey =true, ColumnName = "cid")] public int Id { get; set; } public string Name { get; set; } public int InfoId { get; set; } [Navigate(NavigateType.OneToOne, nameof(InfoId))] public Country111Info Info { get; set; } [Navigate(NavigateType.OneToMany,nameof(Province1111.CountryId))] public List Provinces { get; set; } } public class Country111Info { [SqlSugar.SugarColumn(IsPrimaryKey =true,ColumnName = "infoId")] public int Id { get; set; } public string Name { get; set; } } [SugarTable("Province_1111")] public class Province1111 { [SqlSugar.SugarColumn( ColumnName = "pid")] public int Id { get; set; } public string Name { get; set; } [SugarColumn(ColumnName = "coid")] public int CountryId { get; set; } } } }