连表动态查询,是否有条件支持这样写 返回

SqlSugar 沟通中
2 416
var paymentList = db.Queryable<FmsPayment>()
     .LeftJoin<StaffUser>((fp, creator) => fp.StaffUserId == creator.Id)
     .LeftJoin<StaffUser>((fp, creator,auditor) => fp.AuditStaffUserId == auditor.Id)
     .Where((fp, creator,auditor) => fp.CreateTime > 1776249394)
     .Select((fp, creator,auditor) => new
     {
         fp.Id, 
         fp.Name, 
         fp.PayAmount, 
         fp.CreateTime,
         Creator = new
         {
             creator.Id, 
             creator.Username
         },
         Auditor = new
         {
             auditor.Id, 
             auditor.Username
         }
     })
     .ToListAsync();
SELECT 

auditor.id AS "Auditor.Id",
auditor.username AS "Auditor.Username",
creator.id AS "Creator.Id",
creator.username AS "Creator.Username",
fp.create_time AS CreateTime ,
fp.id AS Id,
fp.name AS Name,
fp.pay_amount AS PayAmount

FROM fms_payments fp

LEFT JOIN staff_users creator ON creator.id = fp.staff_user_id
LEFT JOIN staff_users auditor ON auditor.id = fp.audit_staff_user_id



热忱回答2

  • hp9999 hp9999 VIP0
    2026/4/15

    用导航即可

    0 回复
  • hoperce hoperce VIP0
    2026/4/15

    导航会把所有字段列出来,实际场景并不需要

    0 回复