I have 2 tables: TableA
and TableB
in MySQL on which I am trying to do some CRUD operations in .NET. I have written a function to insert a new row in TableA
followed by updating a single row in TableB
. The incoming request consists of an incommingID
parameter. The insert command works as expected but the update command on TableB
dosen’t do anything. It doesn’t even give any error. The method is given below:
public int SomeMethod(int incommingID)
{
MyDBContext db = new MyDBContext();
TableAModel rowA = new TableAModel
{
// ...data to be inserted
}
db.TableA.Add(rowA);
var query = from tableData in db.TableB
where tableData.id == incommingID
select tableData;
var rowToBeUpdated = query.SingleOrDefault();
if(rowToBeUpdated != null)
{
// isAccepted is false for all rows and is to be set true for this particular id but
// when updated, the changes don't reflect and the row still has isAccepted as false.
rowToBeUpdated.isAccepted = true;
db.SaveChanges();
}
return incommindID;
}
I even tried wrapping the code with a try…catch but it didn’t throw any errors. What is the reason that TableA
insert is working as expected but TableB
update isn’t working?
2
Answers
as far as i know when you make a table in mysql, and set the data type to boolean it transfers to TINYINT. try to set it to 1.
Firstly, you can use try catch blocks to be able to see exception if you have.
An other option, you may have disabled the ChangeTracker value somewhere.
Try this;
The last one
Ensure that there are no transactions preventing the changes from being committed. If there is an ongoing transaction that is not committed, changes may not be persisted to the database.