0

When Table1.Foo changes, I want to update a column on Table2. What would be easiest is if I could just "run" some custom SQL after the update to Table1 is committed, however there doesn't seem to be a place to do this.

It seems the "recommended" solution is to override the SaveChanges() method of EntitiesContext. However, I have several dozen models and hundreds of columns - it seems rather hacky and inefficient to execute code every time any model anywhere is changed, and then say "If it happens to be this property of this model, then do this.."

My first approach was to use a database trigger, which would be great. Unfortunately, Oracle doesn't appear to support this type of updating I need to do in a trigger.

Any other ideas for this sort of thing?

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326

4 Answers4

1

Are you sure you can't just add a trigger that calls a stored procedure like this:

http://searchoracle.techtarget.com/answer/Calling-a-stored-procedure-from-a-trigger

It'll let you put in the functionality you want without disturbing your dozens of models/programs.

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • Man I wish, that would be an ideal solution. However, since I need to query other values from the same table and those values are in a state of flux, it isn't supported. See Justin Cave's response to my question here: http://stackoverflow.com/questions/7507636/oracle-problem-creating-trigger-that-updates-another-table – Mike Christensen Sep 22 '11 at 16:39
0

you can create a stored procedure and call it in a very easy way... I think

0

use the POCO feature in EF 4.0.

check this link: http://www.devart.com/blogs/dotconnect/index.php/entity-framework-tips-and-tricks-part-2.html

specially this section 'ObjectContext.ExecuteStoreQuery'

Boomer
  • 1,468
  • 1
  • 15
  • 19
0

You can create a partial class for the given entity in your project, if you did not create one.

In your partial class, you override PropertyChangedEvent handler to update other table. I don't think you have to create a stored procedure for that.

  • I'll look into this method. So if I change a property in another table, the Entity framework will just automatically track this change and update everything when the transaction commits? – Mike Christensen Sep 28 '11 at 15:38