Reputation: 78004
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?
Upvotes: 20
Views: 8465
Reputation: 11
The accepted answer didn't solve my problem but I found another way and it was solved.
If It couldn't solve your problem you can try that:
ExecuteFunction<MyClass>("YourDbContextName.YourProcedureName",parameters);
Upvotes: 1
Reputation: 111
I was getting this error as well and it turned out to be the connection strings. In my situation I had two separate entity models that had the same entity model name.
<connectionStrings>
<add name="EntityModelNameEntities" connectionString="metadata=res://My.Namespace.FirstOne/EntityModelName.csdl|res://My.Namespace.FirstOne/EntityModelName.ssdl|res://My.Namespace.FirstOne/EntityModelName.msl;provider=System.Data.SqlClient;provider connection string="Data Source=...."" providerName="System.Data.EntityClient" />
<add name="OtherModelEntities" connectionString="metadata=res://*/EntityModelName.csdl|res://*/EntityModelName.ssdl|res://*/EntityModelName.msl;provider=System.Data.SqlClient;provider connection string="Data Source=...."" providerName="System.Data.EntityClient" />
</connectionStrings>
When OtherModelEntities was trying to find the model resources it ended up matching on the one in My.Namespace.FirstOne due to the use of the * wildcard matching. To correct this I updated the OtherModelEntities connection string to include the namespace like this:
<add name="OtherModelEntities" connectionString="metadata=res://My.Namespace.SecondOne/EntityModelName.csdl|res://My.Namespace.SecondOne/EntityModelName.ssdl|res://My.Namespace.SecondOne/EntityModelName.msl;provider=System.Data.SqlClient;provider connection string="Data Source=...."" providerName="System.Data.EntityClient" />
Upvotes: 8
Reputation: 78004
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.
Upvotes: 26