using SqlSugar; using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OrmTest { internal class UnitNavOneToManyDTO { public static void Init() { Test(NewUnitTest.Db).GetAwaiter().GetResult(); } private static async Task Test(ISqlSugarClient db) { db.CodeFirst.InitTables(); db.DbMaintenance.TruncateTable(); db.CodeFirst.InitTables(); db.DbMaintenance.TruncateTable(); { List jyywHonor = new List(); jyywHonor.Add(new JyywHonorEntity { Id = "451911727693431045", PeopleId = "3208101010101", Date = DateTime.Now, ProvideUnit = "授予单位", Level = "市级", CollectionUnit = "446454257080598469", }); await db.Insertable(jyywHonor).ExecuteCommandAsync(); List jyywEquity = new List(); jyywEquity.Add(new JyywEquityEntity { Id = "451911727668265221", PeopleId = "3208101010101", Type = "抚恤", Date = DateTime.Now, ProvideUnit = "局", Level = "市级", Money = 500, CollectionUnit = "446454257080598469", }); jyywEquity.Add(new JyywEquityEntity { Id = "451911727668265222", PeopleId = "3208101010101", Type = "抚恤", Date = DateTime.Now, ProvideUnit = "局", Level = "市级", Money = 500, CollectionUnit = "446454257080598469", }); jyywEquity.Add(new JyywEquityEntity { Id = "451911727668265223", PeopleId = "3208101010101", Type = "抚恤", Date = DateTime.Now, ProvideUnit = "局", Level = "市级", Money = 500, CollectionUnit = "446454257080598469", }); await db.Insertable(jyywEquity).ExecuteCommandAsync(); List jyywMember = new List(); jyywMember.Add(new JyywMemberEntity { Id = "451911727714402565", PeopleId = "3208101010101", MemberName = "王", Relationship = "母亲", BirthDate = DateTime.Now, Hometown = "上海青浦", WorkUnit = "市局", CollectionUnit = "446454257080598469", }); jyywMember.Add(new JyywMemberEntity { Id = "452011164222619589", PeopleId = "3208101010101", MemberName = "1", Relationship = "父亲", BirthDate = DateTime.Now, Hometown = "2", WorkUnit = "3", CollectionUnit = "446454257080598469", }); await db.Insertable(jyywMember).ExecuteCommandAsync(); List jyywPeople = new List(); jyywPeople.Add(new JyywPeopleEntity { Id = "451911727638905093", CollectionDate = DateTime.Now, CollectionUnit = "446454257080598469", Name = "王", Status = "健在", Sex = "男", Nation = "汉族", Hometown = "AAAA", IdNumber = "3208101010101", Phone = "15251711733", WorkUnit = "公司", Addr = "路", BriefStoryTag = "[\"和歹徒搏斗\"]", BriefStoryContent = "简要事迹", SacrificeInjuryTag = "[\"和歹徒搏斗\",\"帮助困难\"]", SacrificeInjuryContent = "牺牲或伤残情况", PracticalDifficulties = "家庭生活实际困难", BasicLife = "无", MedicalTreatment = "无", Employment = "无", Education = "无", Housing = "无", }); jyywPeople.Add(new JyywPeopleEntity { Id = "452011164168093637", CollectionDate = DateTime.Now, CollectionUnit = "446454257080598469", Name = "王", Status = "健在", Sex = "男", Nation = "汉族", Hometown = "AAAA", IdNumber = "3208101010101", Phone = "15251711733", WorkUnit = "公司", Addr = "路", BriefStoryTag = "[\"和歹徒搏斗\"]", BriefStoryContent = "简要事迹", SacrificeInjuryTag = "[\"和歹徒搏斗\",\"帮助困难\"]", SacrificeInjuryContent = "牺牲或伤残情况", PracticalDifficulties = "家庭生活实际困难", BasicLife = "无", MedicalTreatment = "无", Employment = "无", Education = "无", Housing = "无", }); await db.Insertable(jyywPeople).ExecuteCommandAsync(); List jyywReport = new List(); jyywReport.Add(new JyywReportEntity { Id = "451911727731179781", PeopleId = "3208101010101", Date = DateTime.Now, ProvideUnit = "电视台", Level = "市级", CollectionUnit = "446454257080598469", }); await db.Insertable(jyywReport).ExecuteCommandAsync(); } var data = await db.Queryable() .Includes(it => it.JyywEquityList) .Includes(it => it.JyywHonorList) .Includes(it => it.JyywMemberList) .Includes(it => it.JyywReportList) .Where(it => it.Id == "451911727638905093") .Select(it => new { it = it.Id, tableField142 = it.JyywEquityList, tableField125 = it.JyywHonorList, tableField131 = it.JyywMemberList, tableField155 = it.JyywReportList, }).ToListAsync(); if (data.First().it != "451911727638905093" || data.First().tableField125.Count == 0) { throw new Exception("unit error"); } } /// /// 权益保护实体. /// [SugarTable("jyyw_equity")] public class JyywEquityEntity { /// /// 主键. /// [SugarColumn(ColumnName = "F_Id", IsPrimaryKey = true)] public string Id { get; set; } /// /// 人员表主键. /// [SugarColumn(ColumnName = "F_PeopleId", ColumnDescription = "人员表主键", IsNullable = true)] public string PeopleId { get; set; } /// /// 权益类型. /// [SugarColumn(ColumnName = "F_Type", ColumnDescription = "权益类型", IsNullable = true)] public string Type { get; set; } /// /// 发放时间. /// [SugarColumn(ColumnName = "F_Date", ColumnDescription = "发放时间", IsNullable = true)] public DateTime Date { get; set; } /// /// 发放单位. /// [SugarColumn(ColumnName = "F_ProvideUnit", ColumnDescription = "发放单位", IsNullable = true)] public string ProvideUnit { get; set; } /// /// 级别. /// [SugarColumn(ColumnName = "F_Level", ColumnDescription = "级别", IsNullable = true)] public string Level { get; set; } /// /// 金额. /// [SugarColumn(ColumnName = "F_Money", ColumnDescription = "金额", IsNullable = true)] public decimal Money { get; set; } /// /// 备注. /// [SugarColumn(ColumnName = "F_Remark", ColumnDescription = "备注", IsNullable = true)] public string Remark { get; set; } /// /// 采集单位. /// [SugarColumn(ColumnName = "F_CollectionUnit", ColumnDescription = "采集单位", IsNullable = true)] public string CollectionUnit { get; set; } } /// /// 曾获荣誉实体. /// [SugarTable("jyyw_honor")] public class JyywHonorEntity { /// /// 主键. /// [SugarColumn(ColumnName = "F_Id", IsPrimaryKey = true)] public string Id { get; set; } /// /// 人员表主键. /// [SugarColumn(ColumnName = "F_PeopleId", ColumnDescription = "人员表主键", IsNullable = true)] public string PeopleId { get; set; } /// /// 授予时间. /// [SugarColumn(ColumnName = "F_Date", ColumnDescription = "授予时间", IsNullable = true)] public DateTime Date { get; set; } /// /// 授予单位. /// [SugarColumn(ColumnName = "F_ProvideUnit", ColumnDescription = "授予单位", IsNullable = true)] public string ProvideUnit { get; set; } /// /// 荣誉级别. /// [SugarColumn(ColumnName = "F_Level", ColumnDescription = "荣誉级别", IsNullable = true)] public string Level { get; set; } /// /// 备注. /// [SugarColumn(ColumnName = "F_Remark", ColumnDescription = "备注", IsNullable = true)] public string Remark { get; set; } /// /// 采集单位. /// [SugarColumn(ColumnName = "F_CollectionUnit", ColumnDescription = "采集单位", IsNullable = true)] public string CollectionUnit { get; set; } } /// /// 家庭成员实体. /// [SugarTable("jyyw_member")] public class JyywMemberEntity { /// /// 主键. /// [SugarColumn(ColumnName = "F_Id", IsPrimaryKey = true)] public string Id { get; set; } /// /// 人员表主键. /// [SugarColumn(ColumnName = "F_PeopleId", ColumnDescription = "人员表主键", IsNullable = true)] public string PeopleId { get; set; } /// /// 家庭成员姓名. /// [SugarColumn(ColumnName = "F_MemberName", ColumnDescription = "家庭成员姓名", IsNullable = true)] public string MemberName { get; set; } /// /// 关系. /// [SugarColumn(ColumnName = "F_Relationship", ColumnDescription = "关系", IsNullable = true)] public string Relationship { get; set; } /// /// 出生年月. /// [SugarColumn(ColumnName = "F_BirthDate", ColumnDescription = "出生年月", IsNullable = true)] public DateTime BirthDate { get; set; } /// /// 籍贯. /// [SugarColumn(ColumnName = "F_Hometown", ColumnDescription = "籍贯", IsNullable = true)] public string Hometown { get; set; } /// /// 工作单位及职业. /// [SugarColumn(ColumnName = "F_WorkUnit", ColumnDescription = "工作单位及职业", IsNullable = true)] public string WorkUnit { get; set; } /// /// 采集单位. /// [SugarColumn(ColumnName = "F_CollectionUnit", ColumnDescription = "采集单位", IsNullable = true)] public string CollectionUnit { get; set; } } /// /// jyyw_people实体. /// [SugarTable("jyyw_people")] public class JyywPeopleEntity { /// /// 主键. /// [SugarColumn(ColumnName = "F_Id", IsPrimaryKey = true)] public string Id { get; set; } /// /// 采集时间. /// [SugarColumn(ColumnName = "F_CollectionDate", ColumnDescription = "采集单位", IsNullable = true)] public DateTime CollectionDate { get; set; } /// /// 采集单位. /// [SugarColumn(ColumnName = "F_CollectionUnit", ColumnDescription = "采集单位", IsNullable = true)] public string CollectionUnit { get; set; } /// /// 姓名. /// [SugarColumn(ColumnName = "F_Name", ColumnDescription = "姓名", IsNullable = true)] public string Name { get; set; } /// /// 人员状态. /// [SugarColumn(ColumnName = "F_Status", ColumnDescription = "人员状态", IsNullable = true)] public string Status { get; set; } /// /// 性别. /// [SugarColumn(ColumnName = "F_Sex", ColumnDescription = "性别", IsNullable = true)] public string Sex { get; set; } /// /// 民族. /// [SugarColumn(ColumnName = "F_Nation", ColumnDescription = "民族", IsNullable = true)] public string Nation { get; set; } /// /// 籍贯. /// [SugarColumn(ColumnName = "F_Hometown", ColumnDescription = "籍贯", IsNullable = true)] public string Hometown { get; set; } /// /// 身份证号码. /// [SugarColumn(ColumnName = "F_IdNumber", ColumnDescription = "身份证号码", IsNullable = true)] public string IdNumber { get; set; } /// /// 手机号. /// [SugarColumn(ColumnName = "F_Phone", ColumnDescription = "手机号", IsNullable = true)] public string Phone { get; set; } /// /// 工作单位及职业(职务). /// [SugarColumn(ColumnName = "F_WorkUnit", ColumnDescription = "工作单位及职业(职务)", IsNullable = true)] public string WorkUnit { get; set; } /// /// 户籍及家庭住址. /// [SugarColumn(ColumnName = "F_Addr", ColumnDescription = "户籍及家庭住址", IsNullable = true)] public string Addr { get; set; } /// /// 简要事迹-标签. /// [SugarColumn(ColumnName = "F_BriefStoryTag", ColumnDescription = "简要事迹-标签", IsNullable = true)] public string BriefStoryTag { get; set; } /// /// 简要事迹-内容. /// [SugarColumn(ColumnName = "F_BriefStoryContent", ColumnDescription = "简要事迹-内容", IsNullable = true)] public string BriefStoryContent { get; set; } /// /// 在见义勇为中牺牲或伤残情况-标签. /// [SugarColumn(ColumnName = "F_SacrificeInjuryTag", ColumnDescription = "在见义勇为中牺牲或伤残情况-标签", IsNullable = true)] public string SacrificeInjuryTag { get; set; } /// /// 在见义勇为中牺牲或伤残情况-内容. /// [SugarColumn(ColumnName = "F_SacrificeInjuryContent", ColumnDescription = "在见义勇为中牺牲或伤残情况-内容", IsNullable = true)] public string SacrificeInjuryContent { get; set; } /// /// 家庭生活实际困难. /// [SugarColumn(ColumnName = "F_PracticalDifficulties", ColumnDescription = "家庭生活实际困难", IsNullable = true)] public string PracticalDifficulties { get; set; } /// /// 基本生活. /// [SugarColumn(ColumnName = "F_BasicLife", ColumnDescription = "基本生活", IsNullable = true)] public string BasicLife { get; set; } /// /// 医疗. /// [SugarColumn(ColumnName = "F_MedicalTreatment", ColumnDescription = "医疗", IsNullable = true)] public string MedicalTreatment { get; set; } /// /// 就业. /// [SugarColumn(ColumnName = "F_Employment", ColumnDescription = "就业", IsNullable = true)] public string Employment { get; set; } /// /// 教育. /// [SugarColumn(ColumnName = "F_Education", ColumnDescription = "教育", IsNullable = true)] public string Education { get; set; } /// /// 住房. /// [SugarColumn(ColumnName = "F_Housing", ColumnDescription = "住房", IsNullable = true)] public string Housing { get; set; } /// /// . /// [Navigate(NavigateType.OneToMany, nameof(JyywEquityEntity.PeopleId), nameof(IdNumber))] public List JyywEquityList { get; set; } /// /// . /// [Navigate(NavigateType.OneToMany, nameof(JyywHonorEntity.PeopleId), nameof(IdNumber))] public List JyywHonorList { get; set; } /// /// . /// [Navigate(NavigateType.OneToMany, nameof(JyywMemberEntity.PeopleId), nameof(IdNumber))] public List JyywMemberList { get; set; } /// /// . /// [Navigate(NavigateType.OneToMany, nameof(JyywReportEntity.PeopleId), nameof(IdNumber))] public List JyywReportList { get; set; } } /// /// 媒体宣传实体. /// [SugarTable("jyyw_report")] public class JyywReportEntity { /// /// 主键. /// [SugarColumn(ColumnName = "F_Id", IsPrimaryKey = true)] public string Id { get; set; } /// /// 人员表主键. /// [SugarColumn(ColumnName = "F_PeopleId", ColumnDescription = "人员表主键", IsNullable = true)] public string PeopleId { get; set; } /// /// 宣传时间. /// [SugarColumn(ColumnName = "F_Date", ColumnDescription = "宣传时间", IsNullable = true)] public DateTime Date { get; set; } /// /// 媒体名称或频道. /// [SugarColumn(ColumnName = "F_ProvideUnit", ColumnDescription = "媒体名称或频道", IsNullable = true)] public string ProvideUnit { get; set; } /// /// 媒体等级. /// [SugarColumn(ColumnName = "F_Level", ColumnDescription = "媒体等级", IsNullable = true)] public string Level { get; set; } /// /// 备注. /// [SugarColumn(ColumnName = "F_Remark", ColumnDescription = "备注", IsNullable = true)] public string Remark { get; set; } /// /// 采集单位. /// [SugarColumn(ColumnName = "F_CollectionUnit", ColumnDescription = "采集单位", IsNullable = true)] public string CollectionUnit { get; set; } } /// /// jyyw_people详情输出参数. /// public class JyywPeopleDetailOutput { /// /// 主键. /// public string id { get; set; } /// /// 采集时间. /// public string collectionDate { get; set; } /// /// 采集单位. /// public string collectionUnit { get; set; } /// /// 姓名. /// public string name { get; set; } /// /// 人员状态. /// public string status { get; set; } /// /// 性别. /// public string sex { get; set; } /// /// 民族. /// public string nation { get; set; } /// /// 籍贯. /// public string hometown { get; set; } /// /// 身份证号码. /// public string idNumber { get; set; } /// /// 手机号. /// public string phone { get; set; } /// /// 工作单位及职业(职务). /// public string workUnit { get; set; } /// /// 户籍及家庭住址. /// public string addr { get; set; } /// /// 简要事迹-标签. /// public string briefStoryTag { get; set; } /// /// 简要事迹-内容. /// public string briefStoryContent { get; set; } /// /// 在见义勇为中牺牲或伤残情况-标签. /// public string sacrificeInjuryTag { get; set; } /// /// 在见义勇为中牺牲或伤残情况-内容. /// public string sacrificeInjuryContent { get; set; } /// /// 家庭生活实际困难. /// public string practicalDifficulties { get; set; } /// /// 基本生活. /// public string basicLife { get; set; } /// /// 医疗. /// public string medicalTreatment { get; set; } /// /// 就业. /// public string employment { get; set; } /// /// 教育. /// public string education { get; set; } /// /// 住房. /// public string housing { get; set; } /// /// . /// public List tableField142 { get; set; } /// /// . /// public List tableField125 { get; set; } /// /// . /// public List tableField131 { get; set; } /// /// . /// public List tableField155 { get; set; } } /// /// 权益保护详情输出参数. /// public class JyywEquityDetailOutput { /// /// 人员表主键. /// public string peopleId { get; set; } /// /// 权益类型. /// public string type { get; set; } /// /// 发放时间. /// public string date { get; set; } /// /// 发放单位. /// public string provideUnit { get; set; } /// /// 级别. /// public string level { get; set; } /// /// 金额. /// public decimal money { get; set; } /// /// 采集单位. /// public string collectionUnit { get; set; } } /// /// 曾获荣誉详情输出参数. /// public class JyywHonorDetailOutput { /// /// 人员表主键. /// public string peopleId { get; set; } /// /// 授予时间. /// public string date { get; set; } /// /// 授予单位. /// public string provideUnit { get; set; } /// /// 荣誉级别. /// public string level { get; set; } /// /// 采集单位. /// public string collectionUnit { get; set; } } /// /// 家庭成员详情输出参数. /// public class JyywMemberDetailOutput { /// /// 人员表主键. /// public string peopleId { get; set; } /// /// 家庭成员姓名. /// public string memberName { get; set; } /// /// 关系. /// public string relationship { get; set; } /// /// 出生年月. /// public string birthDate { get; set; } /// /// 籍贯. /// public string hometown { get; set; } /// /// 工作单位及职业. /// public string workUnit { get; set; } /// /// 采集单位. /// public string collectionUnit { get; set; } } /// /// 媒体宣传详情输出参数. /// public class JyywReportDetailOutput { /// /// 人员表主键. /// public string peopleId { get; set; } /// /// 宣传时间. /// public string date { get; set; } /// /// 媒体名称或频道. /// public string provideUnit { get; set; } /// /// 媒体等级. /// public string level { get; set; } /// /// 采集单位. /// public string collectionUnit { get; set; } } } }