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; } } } }