diff --git a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs index 543c2df24..75ff1ff51 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Main.cs @@ -30,6 +30,7 @@ namespace OrmTest } public static void Init() { + Unitadfasfa.Init(); UnitOneToMany1231123.Init(); OneToManyInString.Init(); UnitSplitTask.Init(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitadfasfa.cs b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitadfasfa.cs new file mode 100644 index 000000000..e1a5ac9fa --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitadfasfa.cs @@ -0,0 +1,116 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; +using System.Linq; +namespace OrmTest +{ + internal class Unitadfasfa + { + public static void Init() + { + var db = NewUnitTest.Db; + var list=new string[] {"a","b" }; + //如何存在删掉重新建新表 + if (db.DbMaintenance.IsAnyTable("Product", false)) + { + db.DbMaintenance.DropTable(); + } + db.CodeFirst.InitTables(); + db.Queryable() + .Where(it => it.Authentications.Any(s => list.Contains(s.Authentication.CnAuthentication))) + .ToList(); + } + /// + /// 商品 和供应商多对一 + /// + public class Product + { + [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true)] + public long Id { get; set; } + /// + /// 50个字段... + /// + /// + /// 供应商Id + /// + [SugarColumn(ColumnDescription = "供应商Id")] + public long? ManufacturerId { get; set; } + /// + /// 供应商 + /// + [SugarColumn(IsIgnore = true)] + [Navigate(NavigateType.OneToOne, nameof(ManufacturerId))] + public Manufacturer? Manufacturer { get; set; } + } + /// + /// 和供应商一对一 + /// + public class Manufacturer + { + [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true)] + public long Id { get; set; } + /// + /// 供应商名称 + /// + [SugarColumn(ColumnDescription = "供应商名称", Length = 64)] + public string? Name { get; set; } + + /// + /// 认证 + /// + [SugarColumn(IsIgnore = true)] + [Navigate(NavigateType.OneToMany, nameof(ManufacturerAuthentication.ManufacturerId))] + public List? Authentications { get; set; } + } + /// + /// 和供应商认证一对多 + /// + public class ManufacturerAuthentication + { + [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true)] + public long Id { get; set; } + + /// + /// 供应商Id + /// + [Required] + [SugarColumn(ColumnDescription = "供应商Id")] + public long? ManufacturerId { get; set; } + /// + /// 供应商 + /// + [SugarColumn(IsIgnore = true)] + [Navigate(NavigateType.OneToOne, nameof(ManufacturerId))] + public Manufacturer? Manufacturer { get; set; } + /// + /// 认证Id + /// + [SugarColumn(ColumnDescription = "认证Id")] + public long? AuthenticationId { get; set; } + /// + /// 认证 + /// + [SugarColumn(IsIgnore = true)] + [Navigate(NavigateType.OneToOne, nameof(AuthenticationId))] + public DefineManufacturerAuthentication? Authentication { get; set; } + + } + /// + /// 和认证一对一 + /// + public class DefineManufacturerAuthentication + { + [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true)] + public long Id { get; set; } + /// + /// 中文名称 + /// + [SugarColumn(ColumnDescription = "中文名称", Length = 64)] + [MaxLength(64)] + public string? CnAuthentication { get; set; } + + } + } +}