Which of the two ways to check if a record of such TYPE has already been registered is more performative? Are there differences, mistakes? What are the implications? Does using
block only release connection resources or all objects created in its scope? Does the memory used by using
have GC priority? Is there another better way to do this?
Block 1
int valorDoTipo = 5;
Tipo tipo;
using (Contexto contexto = new Contexto())
{
tipo = contexto.Tipo.FirstOrDefault(t => t.ValorDoTipo == valorDoTipo);
}
if (tipo != null)
return true;
else
return false;
Block 2
using (Contexto contexto = new Contexto())
{
int valorDoTipo = 5;
Tipo tipo;
tipo = contexto.Tipo.FirstOrDefault(t => t.ValorDoTipo == valorDoTipo);
if (tipo != null)
return true;
else
return false;
}