I have these two linq queries:
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
};
I am using web API that returns JSON. I want to merge the output of these two queries.
I want to rewrite this code in such a way that comments and follower data should be merged (not combined) with respect to time based on ctime
and startedfollowing
. If a user has a new comment, the comment should come first and if the follower is first, the follower data should come first.I can not use Union() and Concat() because firstly both classes have different members and secondly i dont want both json object to be combined.
Something like this:
{ //comments data },
{ //follower data},
{ //comments data },
{ //comments data },
{ //comments data },
{ //follower data}
So how to do this task?