c# - Entity framework distinct but not on all columns -


i'd make query through entity framework unions contacts 2 different tables, remove duplicates , orders date. issue i'm having around different dates making same contact appear unique. don't want include date in distinct need afterwards ordering. can't ordering first, remove date , perform distinct, because distinct changes ordering. neither can order before union because doesn't ensure ordering after union.

i distinct fields except date, required ordering.

ideally pass comparer distinct ef can't translate sql.

db.packages.select(p => new recent() {     name = p.attention, address1 = p.address1, ... , date = shippingdate }) .concat(db.letters.select(l => new recent() {     name = l.addressedto, address1 = p.address1, ..., date = markeddate }) .distinct() .orderbydescending(r => r.date); 

or problem in sql

select distinct attention, address1, shippingdate packages union select addressedto, address1, markeddate letters order shipmentdate desc 

you should able use groupby want, (not mention group more performant distinct in ef):

db.packages.select(p => new recent() {     name = p.attention, address1 = p.address1, ... , date = shippingdate}) .concat(db.letters.select(l => new recent() {     name = l.addressedto, address1 = p.address1, ..., date = markeddate})) .groupby(p => <parameters group - make record distinct>) .select(g => new {contact = g.key, lastshippingdate = g.max(p => p.shippingdate)}); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -