using System.Configuration; using SqlSugar; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Linq; using System; namespace OrmTest { public class UCustomNavigate01 { public static void Init() { SqlSugarClient db = NewUnitTest.Db; //建表 if (!db.DbMaintenance.IsAnyTable("VIEW_EQ_MODEL_INFO_1", false)) { db.CodeFirst.InitTables(); } db.DbMaintenance.TruncateTable(); //建表 if (!db.DbMaintenance.IsAnyTable("VIEW_EQ_INFO_1", false)) { db.CodeFirst.InitTables(); } db.DbMaintenance.TruncateTable(); //建表 if (!db.DbMaintenance.IsAnyTable("EQ_EDC_ITEM_CONFIG_1", false)) { db.CodeFirst.InitTables(); } db.DbMaintenance.TruncateTable(); //建表 if (!db.DbMaintenance.IsAnyTable("EQ_ALARM_CONFIG_1", false)) { db.CodeFirst.InitTables(); } db.DbMaintenance.TruncateTable(); db.Insertable(new ViewEqInfo() { Iden = "eq01", ModelIden = "eqModel01" }).ExecuteCommand(); db.Insertable(new ViewEqInfo() { Iden = "eq02", ModelIden = "eqModel01" }).ExecuteCommand(); db.Insertable(new ViewEqModel() { ModelIden = "eqModel01" }).ExecuteCommand(); db.Insertable(new EqEdcItemConfig() { Iden = "eqEdc01", ModelIden = "eqModel01" }).ExecuteCommand(); db.Insertable(new EqEdcItemConfig() { Iden = "eqEdc02", ModelIden = "eqModel01" }).ExecuteCommand(); db.Insertable(new EqAlarmConfig() { Iden = "eqAlarm01", ModelIden = "eqModel01" }).ExecuteCommand(); db.Insertable(new EqAlarmConfig() { Iden = "eqAlarm02", ModelIden = "eqModel01" }).ExecuteCommand(); var s1 = db.Queryable() .Includes(a => a.EqEdcItemList) //.Includes(a => a.EqAlarmList) .ToList(); var s2 = db.Queryable() .Includes(s => s.eqModel, a => a.EqEdcItemList) // .Includes(s => s.eqModel, a => a.EqAlarmList) .ToList(); if (s1.First().EqEdcItemList.Count() != s2.First().eqModel.EqEdcItemList.Count()) { throw new Exception("unit error"); } } [SugarTable("VIEW_EQ_MODEL_INFO_1")] public partial class ViewEqModel { public ViewEqModel() { } /// /// /// [SugarColumn(IsPrimaryKey = true, ColumnName = "MODEL_IDEN")] public string ModelIden { get; set; } [Navigate(NavigateType.OneToMany, nameof(EqEdcItemConfig.ModelIden))] public List EqEdcItemList { get; set; } [Navigate(NavigateType.OneToMany, nameof(EqAlarmConfig.ModelIden))] public List EqAlarmList { get; set; } } /// /// /// [SugarTable("VIEW_EQ_INFO_1")] public partial class ViewEqInfo { public ViewEqInfo() { } /// /// 主键 /// [SugarColumn(IsPrimaryKey = true, ColumnName = "IDEN")] public string Iden { get; set; } /// /// 设备型号 /// [SugarColumn(ColumnName = "MODEL_IDEN")] public string ModelIden { get; set; } [SugarColumn(IsIgnore = true)] [Navigate(NavigateType.OneToOne, nameof(ModelIden))] public ViewEqModel eqModel { get; set; } } /// /// /// [SugarTable("EQ_EDC_ITEM_CONFIG_1")] public partial class EqEdcItemConfig { public EqEdcItemConfig() { } /// /// 主键 /// [SugarColumn(IsPrimaryKey = true, ColumnName = "IDEN")] public string Iden { get; set; } /// /// 设备型号 /// [SugarColumn(ColumnName = "MODEL_IDEN")] public string ModelIden { get; set; } } /// /// [SugarTable("EQ_ALARM_CONFIG_1")] public partial class EqAlarmConfig { public EqAlarmConfig() { } /// /// 主键 /// [SugarColumn(IsPrimaryKey = true, ColumnName = "IDEN")] public string Iden { get; set; } /// /// 设备型号 /// [SugarColumn(ColumnName = "MODEL_IDEN")] public string ModelIden { get; set; } } } }