I need to add multiple objects to the database and some objects need another specific object that I've added earlier.
When I make a query to get the object, it comes null.
Example:
var subItem = new SubItem
{
Valor1 = 1,
Valor2 = "Qualquer coisa"
};
repositorioSubItem.Inserir(subItem);
var item = new Item
{
Etc = "Oi",
SubItem = repositorioSubItem.Buscar(e => e.Valor1 = 1); //Valor NULL aqui
};
repositorioItem.Inserir(item);
contexto.SaveChanges();
Why do not you get it?
What do I need to do to query before a SaveChanges
?
Method Buscar
:
public TEntidade Buscar(Expression<Func<TEntidade, bool>> criterios)
{
return Entidades.Where(criterios).SingleOrDefault();
}