Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select all records in table B with same PK and different property values as in table A

I have two tables TA and TB. Both use the same PK (TB is a shadow table of TA). I need to identify all records from TA that are also in TB, but have one or more property values changed.

Sample code:

public class MyData 
{
    public Guid PK { get; set; } = Guid.Empty;
    public int Value1 { get; set; } = 0;
    public int Value2 { get; set; } = 0;
}

What I need is something like find all records R from TA in TB where R(TA).PK == R(TB).PK && (R(TA).Value1 != R(TB).Value1 || R(TA).Value1 != R(TB).Value1)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

However, I have no bloody clue how to write that down, neither as sql nor as Linq statement. I tried a lot of variants, but none was syntactically correct.

>Solution :

var result = ctx.TA.Where(a => ctx.TB.Any(b => a.PK == b.PK && 
  (a.Value1 != b.Value1 || a.Value2 != b.Value2)));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading