Get Record ID in Entity Framework after insert

前端 未结 4 1391
北荒
北荒 2021-02-07 02:34

I\'m developing an ASP.net application using Entity Framework. I\'m using DetailsView to insert data into database. There is a table as Client and its

4条回答
  •  隐瞒了意图╮
    2021-02-07 03:12

    This is what i'm looking for.

    in partial class

    protected void clientDataSource_OnInserted(object sender, EntityDataSourceChangedEventArgs e )
    {
    
        int newPrimaryKey = ((Client)e.Entity).ClientId;
        Debug.WriteLine(" Client ID is " + newPrimaryKey);
    
    }
    

    and added below line in EntityDataSource in aspx page.

    OnInserted="clientDataSource_OnInserted"
    

提交回复
热议问题