Concurrency Exception While adding Record
Kmcnet
691
Reputation points
Hello everyone and thanks for the help in advance. I am using Entity Framework Core in a MVC application to add a record to a Sql database, however I continue to receive the error message "The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded". This particular table is only being accessed by this one application that only adds records. Here is my code:
using (var ctx = new myDbContext())
{
ctx.tbl_Log_UserActivity.Add(new tbl_Log_UserActivity()
{
IPAddress = ipAddress,
Referer = Referer,
UserAgent = userAgent,
TimeEntered = DateTime.Now
});
ctx.SaveChanges();
}
When this didn't work I tried:
var userActivity = new tbl_Log_UserActivity()
{
IPAddress = ipAddress,
Referer = Referer,
UserAgent = userAgent,
TimeEntered = DateTime.Now
};
ctx.tbl_Log_UserActivity.Add(userActivity);
ctx.SaveChanges();
I receive the same error either way. Any help would be appreciated.