Guest User

Untitled

a guest
Jun 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. var fooIds = new List<int> { 2, 3, 4}
  2. var foosToChange = Foo.Where(f => fooIds.Contains(f.Id));
  3. // Update foosToChange and save here
  4.  
  5. var fooIds = new []
  6. {
  7. new { prop1 = "12345", prop2 = 2017111701 },
  8. new { prop1 = "hij", prop2 = 2018060101 }
  9. };
  10.  
  11. var foosToChange = Foo.Where(f => fooIds.Contains(???));
  12.  
  13. var foosToChange = Foo.Where(f => fooIds.Any(x => x.prop1 == f.Id1 && x.prop2 == f.Id2));
  14.  
  15. A[] Foo = new A[]{ new A{ Id1 = "12345", Id2 = "2017111701" }, new A { Id1 = "fakeid", Id2 = "2017111701" } };
  16.  
  17. var res = Foo.Where(f => fooIds.Any(x => x.prop1 == f.Id1 && x.prop2 == f.Id2));
  18.  
  19. // res will return first element
Add Comment
Please, Sign In to add comment