Follow the code below:
using (var db = new Entities())
{
var result = db
.Tabela1
.Select(x => new
{
x.Coluna1,
x.Coluna2
})
.ToList();
foreach (var item in result)
{
if (item.Coluna1 == string.Empty)
{
item.Coluna1 = "Novo Valor";
}
}
db.SaveChanges();
}
Within if
, I get error:
The property or indexer ".Column1" can not be assigned because it is read-only
Here is another code (Works with class "YourClass"):
using (var db = new Entities())
{
var result = db
.Tabela1
.Select(x => new SuaClasse //Aqui
{
x.Coluna1,
x.Coluna2
})
.ToList();
foreach (var item in result)
{
if (item.Coluna1 == string.Empty)
{
item.Coluna1 = "Novo Valor";
}
}
db.SaveChanges();
}
Claase:
public class SuaClasse
{
public string Coluna1 { get; set; }
public string Coluna2 { get; set; }
}
Can you make it work without creating the class (example in the first code)?