当前位置:   article > 正文

SqlSugar 使用 SqlFunc.MappingColumn 做子查询的坑

sqlfunc.mappingcolumn
  1. var table = DbScoped.Sugar.Queryable<Users>()
  2. .Select(user => new MyUserModel
  3. {
  4. Roles_Text = SqlFunc.MappingColumn(default(string), " ( select group_concat(RoleName) from Roles where ID in (select RoleID from Link_UserRole where UserID = user.ID) ) ")
  5. })
  6. .ToList();

如代码所示,需要注意的有两点

第一:子查询需要加小括号

第二:子查询中需要用到的 变量 需要直接写到字符串中,不要拼接!

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号