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?

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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: stackoverflow.com/questions/7507636/…
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.

1 Comment

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?
0

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

3 Comments

The question is, where do I call this stored procedure?
ctx.Database.ExecuteSqlCommand() stackoverflow.com/questions/5474264/…
Yes, I know /how/ to execute a stored proc from .NET - The question is WHERE do you put that logic? After anything in the context changes? That seems hacky.
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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.