mehdi lotfi
mehdi lotfi

Reputation: 11601

Auto Refresh Data In Entity Framework

I using visual studio 2010 and using Entity Framework, and SQL Server 2008 R2. I have after trigger on my table, and When Save one record in table, another column in other table changed. Is it possible to change automatically changed record on my application.

Upvotes: 1

Views: 2294

Answers (3)

mehdi lotfi
mehdi lotfi

Reputation: 11601

I Search for this question and find below code to refresh data in EF : MyModelEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, TbMyRecord);

Upvotes: 0

Pete
Pete

Reputation: 12583

Though, not the answer you are after, I think you should move the "trigger" logic from the database to the application code. That will solve your problem, AND allow you to write a unit test verifying that data is updated correctly.

Upvotes: 1

hanzolo
hanzolo

Reputation: 1150

There is an InsertOnSubmit event that fires as noted here, not sure that's going to help you..

but there are various event fired when saving / modifying entities, but you'd have to bring your "trigger" logic into the code side, and then probably intelligently handle various Entity Changes.. here's more here : How To Execute Business Logic When Saving Changes

and after taking a deeper look at the title of your question it seems that you're trying to get the data from the updated table.. and as the comment suggests.. anything outside the scope of the entity "context" is going to have to be "reloaded". Now if that "loading" code is handled in your "change event" handling, you could accomplish this.. so why not just put all of that logic in your code layer? make the updates to your 2 "entities" and then save them in one swoop..

Upvotes: 2

Related Questions