次の 2 つの linq クエリがあります。
var combo1 = from c in db.comments
join p in db.picture on c.targetpictureid equals p.idpictures
join u in db.users on c.iduser equals u.iduser
select new TCommentDTO
{
idcomments=c.idcomments,
comment1 = c.comment1,
targetpictureid = c.targetpictureid,
ctime = c.ctime,
iduofpic=p.iduser,
iduofcommentor=c.iduser,
profilepicofcommentor=u.profilepic,
usernameofcommentor=u.username,
picFilename=p.picFilename,
picTitle=p.picTitle
};
var combo2 = from f in db.followers
join u in db.users on f.iduser equals u.iduser
select new TfollowerDTO
{
idfollowers = f.idfollowers,
iduser = f.iduser,
targetiduser = f.targetiduser,
startedfollowing = f.startedfollowing,
unoffollower = u.username,
ppoffollower = u.profilepic,
status = u.status
};
JSON を返す Web API を使用しています。これら 2 つのクエリの出力をマージしたいと考えています。
と に基づいて、コメントとフォロワーのデータが時間に関してマージされる (結合されない) ように、このコードを書き直したいと思いctime
ますstartedfollowing
。ユーザーに新しいコメントがある場合は、コメントが最初に来る必要があり、フォロワーが最初の場合はフォロワーデータが最初に来るはずです。最初に両方のクラスに異なるメンバーがあり、次に私がしたくないため、Union() と Concat() を使用できません両方の json オブジェクトを結合します。
このようなもの:
{ //comments data },
{ //follower data},
{ //comments data },
{ //comments data },
{ //comments data },
{ //follower data}
では、このタスクを実行するにはどうすればよいでしょうか。