public static Task<IEnumerable> QueryAsync<TFirst, TSecond, TReturn>()
应用场景:获取带有子集集合的数据
Parent——带有子节点的Model
public class Parent
{
public Parent()
{
Child
= new List<Child>();
}
public string Id
{ get; set; }
public string Name
{ get; set; }
public List
<Child
> Child
{ get; set; }
}
Child——子节点model
public class Child
{
public string Id
{ get; set; }
public string Name
{ get; set; }
}
var lookup
= new Dictionary<string, Parent>();
var sql
= " ";
await db
.QueryAsync<Parent, Child, Parent>(
sql
,
(b
, s
) =>
{
Parenttmp
;
if (!lookup
.TryGetValue(b
.Id
, out tmp
))
{
tmp
= b
;
lookup
.Add(b
.Id
, tmp
);
}
if (s
!= null && (!tmp
.Child
.Any(x
=> x
.Id
== s
.Id
)))
{
tmp
.Child
.Add(s
);
}
return b
;
},
new { ParentId
= id
});
return lookup
.Values
.ToList();
PS:别人的代码,自己解读了一下,如有不对,欢迎━(`∀´)ノ亻!发言,指正(๑‾ ꇴ ‾๑)
转载请注明原文地址:https://tech.qufami.com/read-11504.html