Reputation: 63
I'm using Entity Framework to add new records to the database, everything goes right without any exceptions, but I don't see the new record the database, here is the code:
aSham_MeterReading meterReading = new aSham_MeterReading();
meterReading.TimeStampUTC = reading.TimeOfReading;
meterReading.TimeStampLocal = reading.TimeOfReading.ToLocalTime();
meterReading.Value = reading.Reading * this.Translate(this.MeterUnitsEnum, reading.FactorIndex);
meterReading.Meter = meter;
meterReading.CreateDate = DateTime.Now;
meterReading.UpdateDate = DateTime.Now;
meterReading.RowStatus = "Active";
db.aSham_MeterReading.Add(meterReading);
db.SaveChanges();
The code above is called like 20 times per second, is there any chance that this is related to the problem?
Any help would be appreciated.
Upvotes: 0
Views: 201
Reputation: 111
You can check for the return value from db.SaveChanges() , if it is actually successful , it returns 1 . This will let you know if the operation was actually successful or not
int returnCode = db.SaveChanges();
if(returnCode == 1 )
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine("Something gone wrong");
}
Upvotes: 1