学海无涯

导航

Dapper 查询多个表,映身到对象的实例对象

public async Task<IEnumerable<SplitMergeOrderSourcePlanOrderView>> GetSplitMergeOrderSourcePlanOrderViewAsync(long splitMergeOrderId)
  {
    string sql = "select a.*,b.*  from PlanOrderView a join SplitMergeOrderSource b on a.Id=b.PlanOrderId where a.Id in (select PlanOrderId from SplitMergeOrderSource where SplitMergeOrderId=@splitMergeOrderId)";
    using var conn = _dapper.CreateConnection();
    var result = await conn.QueryAsync<PlanOrderView, SplitMergeOrderSource, SplitMergeOrderSourcePlanOrderView>(sql.ToString(),
      (plan, source) =>
      {
        var result = new SplitMergeOrderSourcePlanOrderView();
        result.PlanOrderView = plan;
        result.SplitMergeOrderSource = source;
        return result;
      }, new { splitMergeOrderId });
    return result;
  }

  

posted on 2023-12-29 16:24  宁静致远.  阅读(50)  评论(0编辑  收藏  举报