Can I return the 'id' field after a LINQ insert?

后端 未结 3 1697
独厮守ぢ
独厮守ぢ 2020-12-12 11:20

When I enter an object into the DB with Linq-to-SQL can I get the id that I just inserted without making another db call? I am assuming this is pretty easy, I just don\'t k

3条回答
  •  执念已碎
    2020-12-12 11:45

    Try this:

    MyContext Context = new MyContext(); 
    Context.YourEntity.Add(obj);
    Context.SaveChanges();
    int ID = obj._ID;
    

提交回复
热议问题