Entity Framework 6 introduce Interception http://entityframework.codeplex.com/wikipage?title=Interception que se puede usar para ajustar el SQL para filtrar los elementos secundarios.
Antes de ejecutar la consulta añadir un interceptor y quitar cuando no es relevante:
var interceptor = new ActiveTagsInterceptor();
DbInterception.Add(interceptor);
documents = context.Documents
.AsQueryable()
.Include(d => d.Tags)
DbInterception.Remove(interceptor);
interceptor de la muestra, que añade "[Activo] = 1 Y" cuando se carga Etiquetas:
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)
{
}
}
Olvidé mencionar que no quiero devolver un tipo anónimo ... Necesito devolver un objeto (o colección) de tipo tblParent. –
Claro, agregué otro fragmento de código que le proporciona un fuerte objeto Parent escrito que contiene todos los elementos secundarios que coinciden con los criterios. Por favor échale un vistazo. –
Esto tiene sentido ... sin embargo, nos hemos movido del reino de la carga ansiosa. –