1

I have an int field in my table set to default 0. I set this field's StoreGeneratedPattern as Computed, but I can't change the value of this field after using SaveChanges(). I have found this answer on same problem, just wondering if there is any better way to do that.

Edit

here is the edmx generated from database (entity framework 6)

enter image description here

this is the result after adding (from my application) some data to table Intervention and as you see IsDeleted set to 0 because of IsDeleted int default 0

enter image description here

and

enter image description here

But after trying something like that

 db.Interventions.Find(currentInterv).IsDeleted = 1;
 db.SaveChanges();

its just didn't work because of StoreGeneratedPattern=Computed

driwand
  • 33
  • 1
  • 2
  • 7

1 Answers1

0

With EDMX-based EF6 the only thing you can do is use a store query to change the column value. With code-first you can create an additional DbContext subtype with different mapping metadata.

But IsDeleted probably shouldn't be StoreGenerated. You can default it to 0 in the database, and in the Entity model by just declaring it as int and not int?.

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
  • well changing int? to int and set StoreGenerated to none solved the problem. but for datetime (also set default value in database's table) I m getting something like this https://i.imgur.com/3t6onSZ.png – driwand Apr 22 '19 at 14:56
  • 1
    That's because that's .NET's default value. You can change it by during SaveChanges as in the answer you linked. – David Browne - Microsoft Apr 22 '19 at 16:11