Using Linq To Sql Classes
do not update the object in the context.
I'm using a Context to get some records and update them.
In my DB I have one record that I want to update...
I get it and I update a field, but the object in the context doesn't change. How is that possible? My code looks like:
using(myPersonalModelContext ctx = new myContext())
{
List<LogIn> notProcessedLogins = ctx.LogIns.Where(login => login.processed == false).ToList(); //Returns 1 record. Ok.
foreach (LogIn notProcessedLogin in notProcessedLogins)
{
notProcessedLogin.processed = true;
}
int notProcessedLoginsCounter = ctx.LogIns.Where(login => login.processed == false).Count(); //Returns 1!!!
ctx.SubmitChanges(); //The object in the context has no change, so it doesn't update nothing.
int notProcessedLoginsCounter = ctx.LogIns.Where(login => login.processed == false).Count(); //Returns 1!!!
}
I'm following the documentation example and looks quite trivial, so I don't get it. Any idea?
In the autogenerated file, I see that is updating _processed
properly:
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_processed", DbType="Bit")]
public System.Nullable<bool> processed
{
get
{
return this._processed;
}
set
{
if ((this._processed != value))
{
this._processed = value;
}
}
}
I have the impression that the object that I'm updating is, for some reason, detached from the Context.