-
Notifications
You must be signed in to change notification settings - Fork 382
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
Duplicating record in Insert (Add or AddAsync) #1621
Comments
@fulviocanducci That is not enough information you are providing. Start with posting the actual (full and exact) version numbers that you are using (just edit your post). Then describe the issue that you are having in more details. |
Thank you, if by any chance relevant information is missing, please let me know and I am at your disposal. @lauxjpn |
@fulviocanducci It appears that you are not using the Pomelo uses (Different casing of the method name.) |
the lab that I set up has Oracle, but the Web has Pomelo, lack of attention for having already tested everything @lauxjpn |
@fulviocanducci So is the issue also appearing using Pomelo, or only using Oracle's provider? |
already test with both and the problem happens with both, from time to time it duplicates record @lauxjpn |
Does that mean that the issue is non-deterministic? How often do you get duplicate record inserts (out of x inserts, y inserts are duplicates)?
Were you able to reproduce the issue with this source code? |
Were you able to reproduce the issue with this source code? SIM
You asked for: "Post us some source code (C#) that produces the issue and post us the SQL that is being generated by EF Core." and that's what I did. Code causing the problem: [HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(AccountSchedule model)
{
if (ModelState.IsValid)
{
using IDbContextTransaction transaction = UnitOfWork.BeginTransaction();
try
{
UnitOfWork.AccountSchedule.Add(model);
UnitOfWork.Commit();
transaction.Commit();
TempData.AddSuccessCreate();
return RedirectToAction(nameof(Edit), new { model.Id });
}
catch (Exception)
{
transaction?.Rollback();
}
}
ViewData.AddError();
await LoadSelectAsync(model);
return View("CreateOrUpdate");
} ie from the web application and problems happen from time to time, but anyway it gets in the way of the project. Remembering that this is a real case, duplication happens, but it is not a daily thing, but sporadic that is, the web application and problems happen from time to time, but in any case it hinders the progress of the project. Remembering that this is a real case, duplication happens, but it is not a daily thing, but sporadic |
Have you confirmed that the action isn't being called twice from the client? Should be easy to verify from the web server logs. |
@fulviocanducci This is going to be an issue in your application code, not in Pomelo. But we will try to help you figure out the issue anyway. As @mguinness suggested, add some additional logging and also just log all EF Core generated SQL. Once you have logged the duplicate INSERT, check the time of the duplicate INSERT against the time of the original INSERT. Also think about typical user issues. For example, if the website does not load in time or as expected, users might just refresh the page (e.g. by pressing |
I'm currently changing the code and removing BeginTransaction and I'm going to check the Logs, I emphasize that the problem is not exactly in the code as it is used on another server and everything works as it should. I will report here what happened. Thank you very much for your collaboration I even have a package for EF that does a non-physical deletion of the record, would that be too difficult to put in Pomelo? (https://www.nuget.org/packages/Canducci.SoftDelete/) |
Any soft delete functionality should be addressed upstream, it's under consideration in dotnet/efcore#22959 so please upvote. |
I realized that after I removed "BeginTransaction" in the code (that is) the transaction control these two days became more stable, I wanted to leave it as an investigation of the new API on the subject |
@mguinness, How would that be, could you explain in more detail? |
Any soft delete functionality should be implemented in EF Core not at the provider level, i.e. this is universal, not provider specific. |
True, very well remembered! |
The System runs in Private Cloud and in the test environment I have no problem, but in the production environment at times the Insert duplicates the information generating the same record but as subsequent keys.
The code demonstrates what I basically do using the layer with Entity Framework. I've done several tests and I can't understand why this duplication sometimes in the registrations, I have a network with more than 20 people working on this Web system
Example
Code
Ouput SQL
Further technical details
MySQL version: 8.0.28
Operating system: Windows Server 2019 Standard Edition
Pomelo.EntityFrameworkCore.MySql version: 5.0.4
Microsoft.AspNetCore.App version: net5.0
The text was updated successfully, but these errors were encountered: