3
I have a problem with a bank search, I will try to explain in the best possible and clearest way.
I have a table Pessoa
and a table Cliente
, the last inherits from Pessoa
, I also have a table Unidade
and a MensagemUnidade
.
The Table MensagemUnidade
has customer relationship as follows :
public class MensagemUnidade
{
public int ClienteId { get; set; }
public int UnidadeId { get; set; }
public virtual Cliente Cliente { get; set; }
public virtual Unidade Unidade { get; set; }
}
I am using the DDD(Domain-Driven Design) model in project construction, when I try to do a research on mensagemServico
he brings the message, brings the company, and even the ClienteId
, but the object Cliente
comes void.
I don’t know what I might have done wrong, on the table Client only has the PessoaId
I added a person and then added that person to the customer, if I search for that person PessoaId
he returns a Cliente
, but it does not bring when seeking message.
My Class Cliente
does not have any connection class (Ex Unit) but my unit class has a Coleção de Clientes
.
If anyone can help me I will be extremely grateful, if information is missing and only and warn.
In the context this contains the following line in the method onModelCreating
:
Configuration.LazyLoadingEnabled = true;
In the example I followed in OnModelCreating
of Contexto
is using a code similar to that
modelBuilder.Entity<ClienteLoja>().HasRequired(v => v.Loja).WithMany(m => m.Clientes).HasForeignKey(f => f.LojaId);
I didn’t put anything like this in my code, is it necessary? if yes why?
EDIT: This is the research I do :
List<MensagemUnidade> mensagens = this.mensagemServico.GetMany(l => l.UnidadeId == unidade.UnidadeAtual && l.OrigemId == (int)enumOrigemMensagem.USUARIO).OrderByDescending(l => l.DataEnvio).Skip(mensagemModel.PaginaAtual * 20).Take(20).ToList();
EDIT 2 : This is the method I use as getMany, there was a previous project here and I need to make a new one and I am using this previous base, in a similar search it brings the necessary information even without the include or something like, everything else is the same as my code except in the context that I have nothing of the kind:
modelBuilder.Entity<ClienteLoja>().HasRequired(v => v.Loja).WithMany(m => m.Clientes).HasForeignKey(f => f.LojaId);
this and my getMany method:
public virtual IQueryable<T> GetMany(Expression<Func<T, bool>> where)
{
return dbset.Where(where);
}
GetMany()
? You have how to post the implementation of this method?– Jéf Bueno
@Williamcézar, advice, give up the RU or the DDD, I would particularly like to keep the EF ;D
– Tobias Mesquita
@Tobymosque I would say that they are not mutually exclusive, just have to do things so that they are minimally organized.
– Bruno Costa
I’m looking for content to try to understand how it works, but it’s very complicated, the rest is all working as it should, I think I’ll leave a custom call in the service where you have include and add the customer, as I have 2 layers that need access to the database , Api and Web ,I use the DDD , to be able to have a semparação of the layers.
– William Cézar
@Brunocosta is possible, but the overhead will take hours of development, your code will not be easier to maintain, you will create artificial limitations to the EF and you will hardly have gained readability. So if there is no gain of Maintainability, Readability, Performance or Time, pq make use of an approach of this?
– Tobias Mesquita
One more: http://answall.com/questions/51536/quando-usar-entity-framework-com-repository-pattern/80696#80696
– Leonel Sanches da Silva
@Brunocosta are almost. Can be considered an anti-standard. I explain here.
– Leonel Sanches da Silva
@Tobymosque Everything depends on what you mean by
ddd
maybe I understandddd
in a different way than yours. It takes hours of development depends only on the abstraction you are creating. I’ve seen that answer and I agree with it. If you want to come to a chat and we have a conversation Xp– Bruno Costa