0

I have a ModelContext with hundreds of models generated with EF DB-First (Scaffold-DbContext).

How can I search through the attributes of the models for those who have a property e.g. objid generically. I could hard-code the check for each model, but that is not practical due to the number of tables / models (big enterprise DB).

Say I didn't know of the Students model below. How could I still check for a property?

using (var context = new MyDbContext())
{
    var students = context.Students
                         .Where(s => s.objid == 1234)                         
                         .ToList();
}  
EricaC
  • 131
  • 1
  • 11
  • 1
    Reflection - [check-if-a-property-exists-in-a-class](https://stackoverflow.com/questions/15341028/check-if-a-property-exists-in-a-class) – Ryan Wilson Feb 16 '23 at 13:46
  • 1
    Look at [EF.Property](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.ef.property?view=efcore-7.0) method. – Alexander Petrov Feb 16 '23 at 13:57

0 Answers0