As you can see in the following image, I have a model with a base class "Person" and both entities "Kunde" and "Techniker" inherit the base class.
Now I've got following problem. When I try to use the method Find to get an object of the derived class Kunde with given ID, it tells me that OfType<TResult>
is a method and isn't valid in this context.
public Kunde GetById(int id)
{
return dbModel.PersonMenge.OfType<Kunde>.Find(id);
}
I've also tried to drop the OfType but it obviously tells me that the object Person cannot be implicitly converted to Kunde.
Is there anything I'm missing here?
It's just two parentheses:
OfType<Kunde>()
But then you can't use Find
any more, because that is a method of DbSet
. You have to use Single
, or dbModel.PersonMenge.Find(id) as Kunde;
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With