Last active
August 29, 2015 13:56
-
-
Save ctrlShiftBryan/9172965 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var findAdds = updated | |
| .GroupJoin(original, l => l.Id, r => r.Id,(l, r) => new { l, r }) | |
| .Where(x => !x.r.Any()) | |
| .Select(x => x.l); | |
| //Result: Person { Id = 4, Name = "Jack" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var findDeletes = original | |
| .GroupJoin(updated, l => l.Id, r => r.Id,(l, r) => new { l, r }) | |
| .Where(x => !x.r.Any()) | |
| .Select(x => x.l); | |
| //Result: Person { Id = 3, Name = "Jill" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //unmodified | |
| var original = new List<Person>() { | |
| new Person() { Id = 1, Name = "Bryan" }, | |
| new Person() { Id = 2, Name = "Randy" }, | |
| new Person() { Id = 3, Name = "Jill" } }; | |
| //modified | |
| var updated = new List<Person>() { | |
| new Person() { Id = 1, Name = "Bryan" }, | |
| new Person() { Id = 2, Name = "Randi" }, //Update Randy to Randi | |
| //Delete Jill | |
| new Person() { Id = 4, Name = "Jack" } }; //Add Jack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var updatesQuery = original | |
| .GroupJoin(updated, u => u.Id, o => o.Id,(left, right) => new { left, right }) | |
| .SelectMany(gj => gj.right.Where(u => u.Name != gj.left.Name), (gj, u) => u); | |
| //Result: Person { Id = 2, Name = "Randi" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var updatesQuery2 = original | |
| .GroupJoin(updated, u => new { u.Id, u.Name }, o => new { o.Id, o.Name }, | |
| (left, right) => new { left, right }) | |
| .Where(x => !x.right.Any()); | |
| //Result: Person { Id = 2, Name = "Randi" } | |
| // Person { Id = 3, Name = "Jill" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment