C#, entity framework, auto increment

前端 未结 5 1272
粉色の甜心
粉色の甜心 2020-12-02 23:07

I\'m learning Entity Framework under VC# 2010.

I have created a simple table for learning purposes, one of the fields is \"id\" type integer, identity set to true. I

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 23:53

    The identity isn't set and incremented just by adding to the entity set... The entity isn't actually saved to the db until you call context.SaveChanges()...

    db.AddToUserSet(user);//Added to EF entity collection
    db.SaveChanges();//INSERT executed in db, Identity set and incremented.
    

提交回复
热议问题