1
I have two relationships Many-To-One in this class (usuario
and projeto
):
public Atividade()
{
Projeto = new Projeto();
StatusAtividade = EStatusAtividade.NaoIniciado;
TipoAtividade = ETipoAtividade.NovaImplementacao;
Usuario = new Usuario();
}
[JsonConverter(typeof(FormatoDataNullableConverter))]
public DateTime? DataHoraFim { get; set; }
[JsonConverter(typeof(FormatoDataNullableConverter))]
public DateTime? DataHoraInicio { get; set; }
public string DescricaoAtividade { get; set; }
public string EstimativaInicialAtividade { get; set; }
public Projeto Projeto { get; set; }
public string NomeProjeto
{
get { return Projeto.Nome; }
}
public Usuario Usuario { get; set; }
public string LoginUsuario
{
get { return Usuario.Login; }
}
public EStatusAtividade StatusAtividade { get; set; }
public string DescricaoStatusAtividade
{
get { return StatusAtividade.Descricao; }
}
public string DescricaoTipoAtividade
{
get { return TipoAtividade.Descricao; }
}
public ETipoAtividade TipoAtividade { get; set; }
public string TituloAtividade { get; set; }
public override bool Equals(object obj)
{
return (obj is Atividade) && (obj as Atividade).Codigo.Equals(Codigo);
}
public override int GetHashCode()
{
return Codigo.GetHashCode();
}
}
In my repository class, set the object load Atividade
as follows:
protected override IQueryable<Atividade> GetEagerLoadConfig()
{
return GetModelContext()
.Include(p => p.Projeto)
.Include(p => p.Usuario);
}
public override Atividade LocalizePorCodigo(long codigo)
{
return GetEagerLoadConfig()
.First(u => u.Codigo.Equals(codigo));
}
How could you configure for that in the load made in the method GetEagerLoadConfig()
, were loaded only the code property of the User and Project objects, rather than fully loading them as is being done? Is it possible?
I understood Gypsy. And in a macro situation (One-To-Many for example) I can use the . Select() method to restrict what I want, right? For in a One-To-Many situation performance would be affected if it carried each object in full.
– Joaquim Magalhães
this superscription of
public override Atividade LocalizePorCodigo(long codigo)
really not necessary, but my 'repository' just encapsulates rules required for my application, and not just implements the standard.– Joaquim Magalhães
@Joaquimmagalhães Restrict within the application, okay. No problems. But no, the performance is very little affected if you carry the object in whole or in parts.
– Leonel Sanches da Silva
@Joaquimmagalhães But you don’t win nothingness with this encapsulation. It is simpler to use the rule directly on
DbContext
. This is reinvention of the wheel.– Leonel Sanches da Silva
Thank you. I will note these points in my studies.
– Joaquim Magalhães