linq - EntityFramework Core Union Select - Null Related Data -
to better picture, trying have feed composed different elements (i'll try make example short possible) :
public class feeddto { public int type { get; set; } public datetime date { get; set; } [jsonproperty(nullvaluehandling = nullvaluehandling.ignore)] public commentdto comment { get; set; } [jsonproperty(nullvaluehandling = nullvaluehandling.ignore)] public likedto { get; set; } public static feeddto setcomment(comment comment, int userid) { return new feeddto { type = activity_feed_type.comment, date = comment.createdate, comment = comment.adapt(userid) }; } public static feeddto setlike(like like, int userid) { return new feeddto { type = activity_feed_type.like, date = like.createdate, = like.adapt(userid) }; } }
and here try query data :
public iqueryable<feeddto> feed(int userid) { var listcomments = context.comments /* includes ... */ .select(x => feeddto.setcomment(x, userid)); var listlikes = context.likes /* includes ... */ .select(x => feeddto.setlike(x, userid)); return listlikes.union(listcomments).orderbydescending(x => x.date); }
the issue :
- when return each 1 alone, without
union
works - when try
union
related data in feeddto methodsnull
Comments
Post a Comment