c# - LINQ Union between two tables with the same fields and then returned in a collection -


i have given trying create linq query retrieve sql server view union between 2 tables. try create linq union.

i have 2 views, memberduespaid , memberduesowed. have same fields in both; (batchno, trandate, debitamount, creditamount, receiptno, checkno, socsecno).

i have helper class in application called membertransaction. has same properties.

how how do union between 2 tables socsecno = ssn passed in? want union 2 tables , return ienumerable collection of membertransaction. after 2 tables unioned want have collection returned ordered trandate in descending order.

you can in linq union query:

var infoquery =     (from paid in db.memberduespaid      select new membertransaction() {         batchno = paid.batchno,         trandate = paid.trandate,         debitamount = paid.debitamount,         creditamount = paid.creditamount,         receiptno = paid.receiptno,         checkno = paid.checkno,         socsecno = paid.socsecno})     .union         (from owed in db.memberduesowed         select new membertransaction() {         batchno = owed.batchno,         trandate = owed.trandate,         debitamount = owed.debitamount,         creditamount = owed.creditamount,         receiptno = owed.receiptno,         checkno = owed.checkno,         socsecno = owed.socsecno}); 

that should return set combined single list.

[edit]

if want distinct values, can after above statement (you can inline if bracket everything, simpler explain):

infoquery = infoquery.distinct(); 

the variable infoquery time populated entirely objects of type membertransaction rather 2 disparate types in union statement.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -