6
What’s the difference between the two ?
With Entitystate:
var registro = db.MinhaTabela.Where(a => a.MeuCampo == "Valor_Antigo").FirstOrDefault();
registro.MeuCampo = "Valor_Novo";
db.Entry(registro).State = EntityState.Modified;
db.SaveChanges();
Sem Entitystate:
var registro = db.MinhaTabela.Where(a => a.MeuCampo == "Valor_Antigo").FirstOrDefault();
registro.MeuCampo = "Valor_Novo";
db.SaveChanges();
Looks like they both work the same thing or it’s different ?
Entry is for objects that are not in context, your first example is not used, because, it does not need to be so, the second is because the object is in context and all changes can be confirmed with
SaveChanges
. An example is in MVC when the object is for change and it is not in context, so you need to use Entry and say that it is a change.– novic
@Virgilionovic, thank you for your comment. Helped me a lot.
– Matheus Miranda