What is difference between change / change2?
using (var context = new NORTHWNDEntities())
{
var change = context.Regions.Where(r => r.RegionDescription == "East").ToList();
var change2 = (from r in context.Regions where r.RegionDescription == "East" select new {r.RegionID, r.RegionDescription }).ToList();
foreach (var p in change2)
{
p.RegionDescription = "West";
}
context.SaveChanges();
}
When I trying to make update on change2 in foreach loop i got error:
Property or indexer '......' cannot be assigned to -- it is read only
It works on previous version with lambda. How Can i change it to work?
RegionDescriptionis a read only property... What about the error is confusing you? It does not work in the lambda either since the lamda is checking equality (==), not performing assignment (=)