I have searched on Google atleast 3 hours but i get all the answers for this issue that are relevant to ADO.NET but i am using Entity framework with visual studio 2012 and mysql.
I want to call a stored procedure having 1 parameter and what i did:
and finally i wrote following code to call that stored procedure.
My Controller Function Body
{ db.SetRecipientsToRefferalPayments(new ObjectParameter("referralId", referralId)); }
My Auto generated class (Model.Context.cs)
public virtual int SetRecipientsToRefferalPayments(ObjectParameter referralId)
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SetRecipientsToRefferalPayments", referralId);
}
and i get following error: The value of EntityCommand.CommandText is not valid for a StoredProcedure command. The EntityCommand.CommandText value must be of the form 'ContainerName.FunctionImportName'.
any one guide me how can i resolve this issue?
It was a very strange problem after spending 2-3 hours finally i figured out the solution.
Steps To Resolve That Issue:
1) Click on [Model].Context.tt File 2) Open with XML Editor or any text editor 3) CTRL + G to location line Number 288 or 277 that was in my case 4) Or Locate following function "ExecuteFunction"
public string ExecuteFunction(EdmFunction edmFunction, string modelNamespace, bool includeMergeOption)
{
var parameters = _typeMapper.GetParameters(edmFunction);
var returnType = _typeMapper.GetReturnType(edmFunction);
var callParams = _code.StringBefore(", ", String.Join(", ", parameters.Select(p => p.ExecuteParameterName).ToArray()));
if (includeMergeOption)
{
callParams = ", mergeOption" + callParams;
}
return string.Format(
CultureInfo.InvariantCulture,
"return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction{0}(\"{1}\"{2});",
returnType == null ? "" : "<" + _typeMapper.GetTypeName(returnType, modelNamespace) + ">",
edmFunction.Name,
callParams);
}
5) change edmFunction.Name to edmFunction.FullName which is the second last line of this function and run your code :)
I faced this issue in EF5 hoping for Microsoft to fix this issue in future EF versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With