Search code examples
asp.netobjectdatasourceentitydatasource

Equivalent of e.ReturnValue in EntityDataSource


I'm using EntityDataSource with DetailsView in my ASP.NET application. I want to get identity column value after inserting the record. ObjectDataSource has e.ReturnValue property I want to know its equivalent in EntityDataSource?


Solution

  • You can subscribe to the Inserted event, which is an EventHandler<EntityDataSourceChangedEventArgs>.

    The EntityDataSourceChangedEventArgs instance has an Entity property, representing the newly inserted entity.

    void EntityDataSource1_Inserted(object sender, EntityDataSourceChangedEventArgs e) {
        YourEntityType newlyAdded = (YourEntityType)e.Entity;
        int newId = newlyAdded.Id;
    }