In the method below, I return some records from my EntityIntermexRegras entity, where it has relation to the .INCLUDE ("Emails and Parameters"). Since EF does not allow filtering in .INCLUDE, would you like to check how to filter these entities?
return ctx.ConsultaIntramexRegras
.Include("Emails")
.Include("Parametros")
.FirstOrDefault(p => p.Id == id);
I need to be filtered as follows:
var regras = ctx.ConsultaIntramexRegras.FirstOrDefault(p => p.Id == id);
var emails = ctx.ConsultaIntramexRegrasEmails.FirstOrDefault(p => p.Id == id && p.Status);
var parametros = ctx.ConsultaIntramexRegrasParametros.FirstOrDefault(p => p.Id == id && p.Status == 1);
The Templates:
public class ConsultaIntramexRegras : EntityBase<int, string>
{
public string Descricao { get; set; }
public int Periodicidade { get; set; }
public int DiaSemanaMes { get; set; }
public int Horario { get; set; }
public bool Status { get; set; }
public int CodigoConsulta { get; set; }
public virtual ICollection<ConsultaIntramexRegrasEmails> Emails{ get; set; }
public virtual ICollection<ConsultaIntramexRegrasParamentros> Parametros { get; set; }
}
public class ConsultaIntramexRegrasEmails : EntityBase<int, string>
{
public string Emails { get; set; }
public bool Status { get; set; }
public int RegrasID { get; set; }
public virtual ConsultaIntramexRegras Regras { get; set; }
}
public class ConsultaIntramexRegrasParamentros : EntityBase<int, string>
{
public int RegrasId { get; set; }
public string Descricao { get; set; }
public int ParametroId { get; set; }
public int SequenciaParametro { get; set; }
public int Tipo { get; set; }
public string Valor { get; set; }
public string TrataData { get; set; }
public int Status { get; set; }
public virtual ConsultaIntramexRegras Regras { get; set; }
}