Given:
using (DataContext ctx = new DataContext(props.ConnectionString))
{
IQueryable<Email> emails = null;
try
{
emails = ctx.Emails.Where(e => !(e.IsLocked || e.IsSent));
foreach (var e in emails)
{
e.IsLocked = true;
}
ctx.SubmitChanges();
}
}
// do something with emails here
Why is emails empty after SubmitChanges()? Is there any way to avoid emptying the Table after IsLocked is set to true?
The table
ctx.Emailsis probably not empty. The collectionemailsis evaluated every time you call it.You could do this if you want to keep the emails return on the initial call: