3
I would like to know how to do a mapping without using ICollection
, or may even be using, but would not want the bank to create a class, just to be able to connect the two classes.
class Pessoa
{
public Guid IdPessoa { get; set; }
public string Nome { get; set; }
}
class Telefone
{
public Guid IdTelefone { get; set; }
public string Numero { get; set; }
public virtual ICollection<Pessoa> PessoasList { get; set; }
}
In mapping the system would create in the bank the entity Pessoa
, the entity Telefone
and create an entity PessoaTelefone
only with Ids, and I would like to create only the entities Pessoa
and Telefone
with a IdPessoa
in how foreign key
in the entity Telefone
. I want the RU to create the class without this weak entity.
Is there a way to do, or I have to map in the nail informing the id on the phone and at persistence recover the recorded id and persist to another entity?
It has to do yes, but I wanted to understand why you do not make a point of using the associative entity, which is just the right.
– Leonel Sanches da Silva
Morrison said there’s a way, but in my view, there’s no way to make an N> N relationship without an association. And if it’s possible, as Morrisson said and I have no basis to argue with him, it seems a bit "Ambi", because the associations were designed for exactly this purpose and want to withdraw it, goes against all the rules of comics, as, integrity and etc. It is possible as the colleague said, but I would not go down that road ever, unless something extremely new, functional and logical came into existence. Association is still, for me, the best way to do it.
– pnet
So @Ciganomorrisonmendez, I’m imagining in terms of performance, and even having to remember an association table that is created automatically by EF, I think the BD ends up bloated taking into account the amount of data that can come if I ask for all the data from my entity along with a second entity, it would cost huge having to Join between two tables + 1 helper, that I see as incorrect since in the class that will have N to 1 only needs the ID of that 1
– Leo
@Leo doesn’t follow what you said. The case of the Fluent API associative entity is a minimal automatic creation, just in case you only need to associate primary keys. From a performance point of view, creating an associative table (which is recommended) or using this minimum entity has identical performance. The associative table still has the advantages of having extra fields to add even more information in the association. If you want, I can answer, but I won’t use this Fluent API approach and explain why.
– Leonel Sanches da Silva
@Leo, you have an A) relationship where a person can have multiple phones, but a phone can only be for one person. B) Or one person has multiple phones and one phone may be for several people. C) Or one person can only have one phone, but one phone can be for several people?
– Pablo Tondolo de Vargas
@Pablovargas, the phone was just an example, but imagine the following, I have in the client/ data relationship, something like Clientephone, Clienteaddressordering, Clientefollwoup, finally I can have N ties to the Customer Entity, and I was wondering if these moorings where would have only the ID of each side, causes me some questions: 1- Tda time I persist a new tel have to record the entity Customer, along with the data of the entity tel already existing? 2- If only the new phone will persist as the persistence is done in that weak entity, since it is not mapped in the ORM ?
– Leo