Oriol Terradas
Oriol Terradas

Reputation: 1798

Custom Insert/Update on Entity Framework and ASP.NET Dynamic Data

I need to customize the insert/update methods for an entity on a CRUD application using ASP.NET Dymanic Data and Entity Framework. I found a solution for an application using Linq To SQL on http://extremedev.blogspot.com.es/2011/03/custom-insertupdate-on-linqtosql-and.html . The customization is for add some business logic.

I didn't find any method to overload on EF or something similar, any suggestion? Is it possible without using triggers or modifing the methods ItemInserted or ItemUpdated on the forms in template pages?

Thx

Upvotes: 1

Views: 2716

Answers (2)

ABMoharram
ABMoharram

Reputation: 1

Try the next link. I think this is what you need http://csharpbits.notaclue.net/2008/05/dynamicdata-automatic-column-update.html

Upvotes: 0

Ash Machine
Ash Machine

Reputation: 9911

The method you referenced above is good, another I have seen is this one:

You can override the SubmitChanges method of your data context and check the set of changes and trap each object and each change type (insert, update, delete)

public override void SubmitChanges(System.Data.Linq.ConflictMode failureMode)
{
    ChangeSet changeset = GetChangeSet();

    foreach (var f in changeset.Inserts.OfType<Foo>())
    {
        DoSomethingSpecial(f);
    }


    private void DoSomethingSpecial(Foo instance)
    {
    ... // do something with another datacontext instance
    }
}

Upvotes: 3

Related Questions