I have a table (and Dto) with two primary keys: int
and string
types:
public class Foo
{
public int Id { get; set; }
public string Data { get; set; }
// other members...
}
So, I have a List<Dto> dtoList
, which I got from one DbContext. I need to get the same dtos in other DbContext. The problem is that the PK is a pair of two columns.
Here's how I did it (and it seems it doesn't work):
public IEnumerable<FooDto> GetFooByPrimaryKeys(List<int> ids, List<string> data)
{
return FooContext.Foo.Where(f => ids.Contains(f.Id) && data.Contains(f.Data));
}
But it returns a little bit more rows that I need. I mean, I'm passing 1300ish pairs and getting 1500ish dtos, so something's not right.
I'm not sure If I took the correct approach.