We help IT Professionals succeed at work.

Entity Framework ExecuteFunction DBContext not refreshing entity?

sbornstein2 asked
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?
Watch Question

Distinguished Expert 2017
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.