I get from DB my entities' list, change some properties and try to Update in in DB.
using (var cn = new SqlConnection(ConnectionString))
{
cn.Open();
var dataPredicate = Predicates.Field<Data>(f => f.Id, Operator.Eq, new [] {1, 2, 3}); // of course it's for an example
var data = cn.GetList<Data>(dataPredicate);
foreach (var element in data)
{
element.Status = StatusEnum.Pending;
element.LastChange = DateTime.Now;
}
foreach (var activeRequest in data)
{
cn.Update(activeRequest);
}
cn.Close();
}
I tried also:
var updated = data.Select(s => new Data
{
Id = s.Id,
CreateDate = s.CreateDate,
ForeignId = s.ForeignId,
LastChange = DateTime.Now,
Status = RequestStatus.Pending
});
And I get InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
I don't have any problem with another operations.
How can I Update it correctly?