0

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.

thehennyy
  • 4,020
  • 1
  • 22
  • 31
  • *I need to filter by date and user* - not sure I understand you: can't you just add these filters into your `Where`? – OfirD Feb 17 '20 at 15:49
  • @HeyJude, I can't add the filters into the where, because the extension Query return and object not the entity. – Eddy Castillo Feb 17 '20 at 20:12
  • ok, so maybe dynamic linq could be helpful here? see for example the code snippet in this [question](https://stackoverflow.com/q/10186683/3002584). – OfirD Feb 17 '20 at 21:06

0 Answers0