Generic Repository Filter Child Properties
<p>I am using a generic repository to query my database <a href="https://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application" rel="nofollow noreferrer">here</a>. All my entities inherit a base class which has a property <code>Active</code>, I set <code>Active</code> to <code>false</code> when the user deletes it. The problem I am facing now is that while the code below works fine for main entity I could not figure out how to return only <code>Active</code> child activities.</p>

<p>I have tried using dynamic linq but not successfully. Is there any way to do this except the most obvious using linq on child entities?</p>

<pre><code> public virtual TEntity GetById(object id,
        Expression&lt;Func&lt;TEntity, bool&gt;&gt; filter = null,
        string includeProperties = "")
    {
        IQueryable&lt;TEntity&gt; query = DbSet;

        if (filter != null)
        {
            query = query.Where(filter);
        }
        if (includeProperties.Length &gt; 0)
        {
            query = includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                .Aggregate(query, (current, includeProperty) =&gt; current.Include(includeProperty));
        }
        else
        {
            return DbSet.Find(id);
        }

        if (query.Any())
        {
            return query.First();
        }
        return query.First();
    }
</code></pre>