c# - Linq union two tables where on has an extra column -
i using union
combine 2 tables audit
, message
. both have same column names except audit
has column called deletedate
. try use union
merge both table if deletedate
not exist, sets deletedate
method null. commented out trying work. when uncomment code, error. there work around? here code
var audit = in _audit.getall() .where(a => a.pint == pint && a.createdate < startdate && (enddate == null || enddate > a.createdate)) select new { a.mint, a.mid, a.desc, a.pstring, a.ptype, a.mtype, a.createdate, // a.deletedate, a.pint }; var message = in _message.getall() .where(a => a.partnerint == partnerint && a.createdate < startdate && (enddate == null || enddate > a.createdate)) select new { a.mint, a.mid, a.desc, a.pstring, a.ptype, a.mtype, a.cdate, a.pint }; var test = in audit.union(message) select new auditmessagesgroup { mint = a.int, mid = a.id, desc = a.desc, pstring = a.pstring, ptype = a.payloadtype, messagetype = a.mtype, createdate = a.createdate, // deletedate = a.deletedate != null ? a.deletedate : null, pint = a.pint };
here error
error cs1929 'iqueryable<<anonymous type: int mint, guid mid, string desc, string pstring, string ptype, mtypes mtype, datetime createdate, datetime deletedate, int? pint>>' not contain definition 'union' , best extension method overload 'parallelenumerable.union<<anonymous type: int mint, guid mid, string desc, string pstring, string ptype, mtypes mtype, datetime createdate, int? pint>> (parallelquery<<anonymous type: int mint, guid mid, string desc, string pstring, string ptype, mtypes mtype, datetime createdate, int? pint>>, ienumerable<<anonymous type: int mint, guid mid, string desc, string pstring, string ptype, mtypes mtype, datetime createdate, int? pint>>)' requires receiver of type 'parallelquery<<anonymous type: int mint, guid mid, string desc, string pstring, string ptype, mtypes mtype, datetime createdate, int? pint>>'
no can't. basic criteria on union column count must match b/w tables. can generate dummy column though bypass. like
considering a.deletedate
datetime
in audit
change message
be
var message = in _message.getall() .where(a => a.partnerint == partnerint && a.createdate < startdate && (enddate == null || enddate > a.createdate)) select new { a.mint, a.mid, a.desc, a.pstring, a.ptype, a.mtype, a.cdate, datetime.now, // dummy column a.pint };
then can perform union
Comments
Post a Comment