I see that Find method in EF requires the arguments to be in the same order as in the HasKey method.
However, what if I have a composite key let’s say ColA ColB ColC. But I only want to find the entities where ColA=5 and ColC=6 – without using LINQ, how would I do it in the most efficient (using Find()) way?
>Solution :
what if I have a composite key let’s say ColA ColB ColC. But I only want to find the entities where ColA=5 and ColC=6
Then you don’t want to do what the Find() method is documented to do:
Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given primary key values
You don’t have all the values that make up the primary key (i.e. pointing to a single record), so you want to search: just build a Where() query instead.
without using LINQ
That is an unnecessary complication.