Let's assume I have a parent entity "Firm" and a handful of child entities that inherit from Firm. Assuming the children are named "RedFirm", "GreenFirm", and "BlueFirm", what is the proper way to query the Firm collection if I want to retrieve only RedFirm and GreenFirm instances?
I know I can do context.Firms.OfType(RedFirm)
, but that only returns the RedFirm instances. Is there anyway to pass a collection of types into OfType or something similar to that? I suppose this can be done through a union but I would think that would be less efficient.
context.Firms.Where(x => x is RedFirm || x is GreenFirm);
You could do something like:
context.Firms.Where(item => (!(item is BlueFirm)));
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