c# - Get Rows with Different Values or Missing from One Table -
i have 2 tables have similar structures. each table has id , firstvalue , secondvalue field. want use linq-to-sql each row that's in tableone , not in tabletwo (based on id) , each row that's in both tables, has different values of firstvalue or secondvalue. sql should like
select tableone.* tableone left outer join tabletwo on tableone.id = tabletwo.id tabletwo.id null or (tabletwo.id not null , (tableone.firstvalue <> tabletwo.firstvalue or tableone.secondvalue <> tabletwo.secondvalue ) ) i've tried
(from in context.tableone b in context.tabletwo.where(b => a.id == b.id && (a.firstvalue != b.firstvalue || a.secondvalue != b.secondvalue)).defaultifempty() select a).tolist(); the problem in query if tableone , tabletwo have matching values, row still gets returned, of tabletwo values null. if row has same values in each table, want not returned @ all.
use groupjoin records second table correspond entity in first table. records either don't have matching records in second table, or have different values:
from in context.tableone join b in context.tabletwo on a.id equals b.id g b in g.defaultifempty() b == null || a.firstvalue != b.firstvalue || a.secondvalue != b.secondvalue select
Comments
Post a Comment