mare
mare

Reputation: 13083

Get changes to entity after update in database

I do this to save new invoince in my Invoices database table:

                // insert invoice into EDM
                edmx.AddToInvoices(newinvoice);
                // save EDM changes to datastore
                edmx.SaveChanges();

I have a trigger on one of the columns that gets computed dynamically by the database. What is the 1) easiest way to get that value out of the database immediatelly after it changes, 2) What is the fastest way?

Thanks

Upvotes: 0

Views: 749

Answers (2)

Craig Stuntz
Craig Stuntz

Reputation: 126547

You can either call Refresh:

MyEntities.Refresh(RefreshMode.StoreWins, someEntity);

...or configure the column in SSDL as store-generated if you never set it on the client.

Upvotes: 1

Dave Swersky
Dave Swersky

Reputation: 34810

Since the Entity Framework can't know anything about the trigger, you'd have to reload the entity with a new query. I strongly recommend finding a different solution, if possible. Triggers can be evil.

Upvotes: 0

Related Questions