2
I need to add several objects to the database and some objects need another specific object that I 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 can’t you get it?
What I need to do to consult before a SaveChanges
?
Method Buscar
:
public TEntidade Buscar(Expression<Func<TEntidade, bool>> criterios)
{
return Entidades.Where(criterios).SingleOrDefault();
}
How is your method
Buscar
?– Maniero
I’ll edit the question and add what’s in mine
Buscar
.– Filipe Oliveira
@bigown, I edited the question and
Entidades
is a Dbset of the entity.– Filipe Oliveira