If you create a context
for each object, as in the first example, you have a problem if the objects are associated, eg Pessoa
and Endereco
, where Endereco
points to Pessoa
. So when you have an instance of Pessoa
on a context
and an instance of Endereco
on another context
and need to connect that Endereco
to Pessoa
, it will give error saying that it can not because it's part of contexts
different.
As in the second example, it is only possible if you can solve everything in one method. Horrible! Example: I can have a method that searches for person by cpf.
Pessoa.pesquisaCpf(string cpf)
In this method I return a person and need to do a search using a context
. Then I need to create a Endereco
, using my same example, and I use the builder of Address, which will create another context. There it will be an error.
To solve all this I am still using only a context
created in the system login. I'm not happy about this, because changes made to the system by one user are not seen by another user on another machine until it resumes login. This I'm trying to fix.