Follow the code below:
using (var db = new Entities())
{
var result = db.
Tabela1
.Where(x => x.Id == 1)
.Select(x => new SuaClasse
{
Coluna1 = x.Coluna1,
})
.FirstOrDefault();
if (result.Coluna1 != string.Empty)
{
result.Coluna2 = "Novo valor";
}
var num = db.SaveChanges(); // aqui retorna 0
}
Class:
public class SuaClasse
{
public string Coluna1 { get; set; }
public string Coluna2 { get; set; }
}
I just want to select a column and then update column value 2, nothing happens, it only returns 0. What did I do wrong?