I have a Payment model with a 'Status' boolean value which defaults to false. Once payment has been made, I need to update that specific payment's 'Status' to true.
Here's the code I've been trying to use to change the specific database entry, but it's just not changing it. What am I doing wrong?
Payment payment = new Payment();
payment = db.Payments.Find(orderId);
db.Entry(payment).State = EntityState.Modified;
payment.Status = true;
db.SaveChanges();
Thanks!
This is what ended up working:
using (var con = new ApplicationDbContext())
{
payment = con.Payments.First(x => x.Id == orderId);
payment.Status = true;
con.Payments.Attach(payment);
var entry = con.Entry(payment);
entry.Property(e => e.Status).IsModified = true;
con.SaveChanges();
}
Payment payment = new Payment();
payment = db.Payments.Find(orderId);
payment.Status = true;
db.Entry(payment).State = EntityState.Modified;
db.SaveChanges();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With