Entity Framework ExecuteFunction DBContext not refreshing entity?

Hello all,

I have a issue where I am using unit of work with entity framework.   When I add or update via a table entity then do a .Add then .Commit(). for example everything works beautifully.   Problem is not I am using a ExecuteFunction call with generic <T> to call a proc but the underlying table entity is not refreshed with that procs update to a record.  

        public ObjectResult<T> StoredProc<T>(string pName, params ObjectParameter[] pParams)
        {
            return ((IObjectContextAdapter)this.DbContext).ObjectContext.ExecuteFunction<T>(pName, pParams);
        }

Any idea how I refresh the underlying entity in this case?
sbornstein2Asked:
Who is Participating?
 
Fernando SotoRetiredCommented:
Hi sbornstein2;

The default behavior of this function is AppendOnly. Therefore if an entity already exist in the data contact then if a record is returned from the call that has the same primary key then it will NOT overwrite the record in the data context. Use the following function,

public ObjectResult<TElement> ExecuteFunction<TElement>(
	string functionName,
	MergeOption mergeOption,
	params ObjectParameter[] parameters
)

Open in new window


and modify the MergeOption to one that will apply the returned values in the way you need. Please see the MergeOption Enumeration web page for the options and there meaning.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.