EntityDataSource Override with custom deletion

I have an ASP.net C # project using EntityDataSource with DevExpress aspxGridView and it works great, letting me select, update, insert and delete. However, instead, I would like to use my own delete method, which instead simply performs the update (just setting the active flag to false), rather than the actual removal.

I have the feeling that I need to use an entitydatasource or grid onrowdeleting object, but this is my first project with Entity Framework 4.0 so that I still find my legs. I have no idea if I need to create a method to override updates in the edmx file behind the file.

Feel any help.

+3
source share
1 answer

You can register a handler in the SavingChanges event to execute the wat you want. something like that:

public partial class AWEntities{ 

partial void OnContextCreated()
{
    this.SavingChanges += new EventHandler(context_SavingChanges);// Register the handler for the SavingChanges event.
}

private static void context_SavingChanges(object sender, EventArgs e)// SavingChanges event handler.
{
    // Get all in Deleted state
    foreach (ObjectStateEntry entry in
        ((ObjectContext)sender).ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))
    {
        if (entry.Entity.GetType() == typeof(MyType)))
        {
            // do what you want.
        }
    }
}
}

http://msdn.microsoft.com/en-us/library/cc716714.aspx

OR You can display the stored procedure to perform the deletion as you want. http://learnentityframework.com/LearnEntityFramework/tutorials/using-stored-procedures-for-insert-update-amp-delete-in-an-entity-data-model/

I like the second option ...

+6
source

Source: https://habr.com/ru/post/1776872/


All Articles