vendredi 14 février 2020

Get data from dbContext dynamically and filtering

I am trying to create an application to extract data from specific tables depending of the dates and other filters. I have a table in the database that records all the tables that I need to get the data. This is the code that I am using to get the data, but I need to filter the data by date and user

DbContext db = new DbContext();
db.ReplicationTables
    .Where(t => tables.Contains(t.TableName))
    .ToList()
    .ForEach(q =>
    {
        var m = db.Query($"Models.{q.TableName}");
    }

In the Query extension, I am using the following code:

public static IQueryable Query(this DbContext context, string entityName) =>
     context.Query(context.Model.FindEntityType(entityName).ClrType);

In the variable "m", I have the full list of the entity but some entities can records millions of rows, for this reason I need to filter by date and user. I at this point i don't know how to fix this. Any help will be appreciate it.





Aucun commentaire:

Enregistrer un commentaire