1

I'm including an entity object inside an other entity object like this:

string[] columnsToRemove = { "Insurance" };
var myQuery = _dataService.GetQuery<Insurance>().Include(i => i.Partner);

I need to remove a column inside myQuery because I get a circular reference on the client when parsing as JSON (Insurance has a column for Partner and Partner has a column for Insurance) but I don't want to use anonymous type definition because I need to create a method that accept an IIncludedQueryable<T,U> and return an IQueryable without the columns that I pass to method with the list of string.

Something like:

IIncludedQueryable<Insurances, Partner>RemoveColumnFromQueryable(typeOf(myQuery) myQuery, string [] columnsToRemove)
{
    // Here I want remove the column(s) from "myQuery"
}

Need something like this but this code is only for the idea:

IIncludedQueryable<Insurances, Partner>RemoveColumnFromQueryable(typeOf(myQuery) myQuery, string [] columnsToRemove)
{
    var attributes = myQuery.GetType().GetProperties();

    foreach (var attribute in attributes)
    {
        foreach (var column in columnsToRemove)
        {
            if (attribute.Name != column)
            {
                // Remove the column from query
                newQuery = myQuery.Where(t => t.GetType().GetProperty(column).Name != column);
            }
        }
    }

    return newQuery;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
DevAB
  • 21
  • 3

0 Answers0