В Entity Framework 6 представлен перехват http://entityframework.codeplex.com/wikipage?title=Interception, который можно использовать для настройки SQL для фильтрации дочерних элементов.
Перед выполнением запроса добавьте перехватчик и удалите его, если он не имеет значения:
var interceptor = new ActiveTagsInterceptor();
DbInterception.Add(interceptor);
documents = context.Documents
.AsQueryable()
.Include(d => d.Tags)
DbInterception.Remove(interceptor);
Образец перехватчика, который добавляет «[Active] = 1 And» при загрузке тегов:
public class ActiveTagsInterceptor : IDbCommandInterceptor
{
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
// [Tag] AS [Extent6] ON => [Tag] AS [Extent6] ON [Extent6].[Active] = 1 And
const string pattern = "\\[Tag\\]\\sAS\\s\\[([\\w]+)\\]\\sON";
const string replacement = "$& [$1].[Active] = 1 And ";
command.CommandText = Regex.Replace(command.CommandText, pattern, replacement);
}
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
}
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
}