-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not Saving Changes #42
Comments
Hi, @mglodack context.Entry(file).State = EntityState.Modified; Be careful because in other cases entity can be detached from context and you should call: context.Set<Models.File>.Attach(file); So, I use the general function with Generic Repository pattern aka: public void Update(TEntity entity)
{
Entities.Attach(entity); // Entities => DbContext.Set<TEntity>
DbContext.Entry(entity).State = EntityState.Modified;
} Also take a look at this answer at SO |
@jonny-novikov Awesome! Thank you for the explanation and SO reference. 😄 |
I'm still not seeing any changes being saved when I call the However, if I call the actual I was under the impression that I no longer need to call Is this still true or am I misunderstanding the library? using (var dbContextScope = _dbContextScopeFactory.Create())
{
// Make changes
dbContextScope.SaveChanges(); // Should call all the DbContext instances SaveChanges methods
} |
Is this code nested within another scope? If so, I assume the above is a long shot, but it is worth eliminating as a potential cause. |
I've got the same issue in case of updating multiple records. I've got more than one row to update, I loop through, attach each entity and then call savechanges on dbcontextscope at the end. as soon as it tries to add another row, attaching entity throws primary key error. But this works fine if I call the dbcontext.savechanges() |
I am having an issue sql sever will not update the object `
This is where i am calling it from
It will add my record ok but not save |
@davidbuckleyni What does any of that have to do with DbContextScope? |
I feel like I'm doing this wrong, but for some reason I can't seem to
SaveChanges
properly.The only way I'm able to actually get the result to be > 0 is to create one of these
_dbContextScopeFactory.CreateWithTransaction(IsolationLevel.Serializable)
My creates work perfectly, but for some reason the updates don't seem to update 😕
Am I going about this the wrong way?
The text was updated successfully, but these errors were encountered: