using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using SqlSugar; using SqlSugar.MongoDb; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MongoDbTest { public class QueryJsonArray4 { public static void Init() { var db = DbHelper.GetNewDb(); db.DbMaintenance.TruncateTable(); db.Insertable(new UserEntity { Id = 111111111111111111, AccountName = "测试", RoleIds = new List { 111111111111111111 }, RoleId = 111111111111111111 }).ExecuteCommand(); db.Insertable(new RolesEntity { Id = 111111111111111111, Name = "测试" }).ExecuteCommand(); var query6 = db.Queryable() .LeftJoin((o, cus) => o.RoleId == cus.Id)//多个条件用&& .Select((o, cus) => new { o, cus }) .ToList(); var a1 = db.Queryable().ToList(); var query5 = db.Queryable() .LeftJoin((o, cus) => o.RoleIds.Contains(cus.Id))//多个条件用&& .Select((o, cus) => new { o.AccountName, cus.Name }) .ToList(); Console.WriteLine("测试完成!"); } /// /// 用户实体 /// [SugarTable("UserComponent")] public class UserEntity { /// /// 主键Id /// [SugarColumn(IsPrimaryKey = true, ColumnName = "_id")] public long Id { get; set; } /// /// 账户名。 /// public string? AccountName { get; set; } = null!; /// /// 角色ID列表 /// public long RoleId { get; set; } /// /// 角色ID列表 /// [SugarColumn(IsJson = true)] public List RoleIds { get; set; } } [SugarTable("RoleComponent")] public class RolesEntity { /// /// 主键Id /// [SugarColumn(IsPrimaryKey = true, ColumnName = "_id")] public long Id { get; set; } public string? Name { get; set; } } } }