I just migrated to mvc net core 3.0 from net core 2.2. Now each time when I am trying to add a new record to database the application creates 9 copies of the same record in DB. I have many tables in my Db and this happens on every one of them. When I was using net core 2.2 everything worked fine.
I am using this code to add a new record to DB:
Db context file:
public virtual async Task<T> AddAsync(T t)
{
Context.Set<T>().Add(t);
await Context.SaveChangesAsync();
return t;
}
This function is called from repository that is called from the controler:
public async Task<IActionResult> AddItem(Item item)
{
.....
}
The controller is called from jquery ajax on the client side and the request to the controller is sending on Add button click.
$(document).on("click", "#addItem",
function (e) {
e.preventDefault();
e.stopPropagation();
var route="...";
var formId="...";
var form = $(formId);
form.validate();
if (!form.valid()) return;
addCompany(route,formId);
});
function addCompany(route, formId) {
alert("start");
var form = $(formId);
var formData = form.serialize();
$.ajax({
async: true,
url: route,
type: "POST",
cache: false,
data: formData,
success: function (result) {
alert("sucess");
},
error: function (xhr) {
alert("error");
}
});
};
I can see on the screen "start" alert 9 times. After a while I can see "success" alert 9 times.
When I am trying to trace the code in debuger, I can see that execution goes chaotically from one function to another - several times one line of code in one function, after this several times in another function. After this it returns to another line of the first function and everything repeates 5-10 times.
And the most weird is that all these 9 records are normaly saved in MS server Db. They have all fields and keys. But when I am opening any of them on the screen It shows that all fields are empty. But using the same application I still can normaly open and see on the screen the records that were saved before I moved to Core 3.0