views:

129

answers:

2

In LINQ to Entities, I map the result set of a stored procedure to an entity.

Within the stored procedure, I execute some update statements and return the result set by running a SELECT query and mapping that result set to the entity.

The database rows get updated correctly, but the entities returned are not reflecting the changes. Instead, the data before the update is getting returned?

Any suggestions?

Thank you. Abe

+1  A: 

Are the entities in question already cached in the context? (i.e. have you queried them already?)

If so, the identity manager will always give you back the original object (rather than creating a new object with the same identity in the same context). Hence for data that has already been read (by other queries) only the identity/primary-key field(s) are considered.

Marc Gravell
I believe so. I query for an object and then call a stored procedure that performs update on that object.Is there any way to force the identity manager to reload the data after the stored procedure is called? Basically, I need the object returned from the stored procedure to reflect the update.Thanks!
AbeP
That I don't know, sorry.
Marc Gravell
+1  A: 

Actually, it turns out the DataContext.Refresh method solved my problem at http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.refresh.aspx

Here's my code:

db.Refresh(System.Data.Objects.RefreshMode.StoreWins, affectedProjectTasks);

Thanks Marc for pointing me to the right direction! Abe

AbeP