The HasKey
method has a signature that has a delegate parameter that receives its entity as a parameter and returns a object
. This means that the content you return (in thesis can be anything because it is a object
) will be your primary key.
An example (example only, do not use this implementation) of what you could do to see what is accepted is to create a method that meets the signature and perform the test:
public object Teste(Entidade a)
{
return 10;
}
builder.HasKey(a => Teste(a));
So the method has the purpose of defining what the primary key of your entity will be, so we do not define a "search criterion" as you commented above because it only needs a return than the Entity Framework will use as the primary key for this entity.