我已经在 Google 上搜索了至少 3 小时,但我得到了与 ADO.NET 相关的这个问题的所有答案,但我正在使用带有 Visual Studio 2012 和 mysql 的 Entity Framework 。
我想调用一个有 1 个参数的存储过程,我做了什么:
我的 Controller 功能体
{
db.SetRecipientsToRefferalPayments(new ObjectParameter("referralId",referralId));
}
我的自动生成类 (Model.Context.cs)
public virtual int SetRecipientsToRefferalPayments(ObjectParameter referralId)
{
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SetRecipientsToRefferalPayments", referralId);
}
我收到以下错误:
EntityCommand.CommandText 的值对于 StoredProcedure 命令无效。 EntityCommand.CommandText 值的格式必须为“ContainerName.FunctionImportName”。
有人指导我如何解决这个问题?
最佳答案
花了 2-3 个小时后,这是一个非常奇怪的问题,我终于找到了解决方案。
解决该问题的步骤:
1)点击【模型】.Context.tt文件
2) 使用 XML 编辑器或任何文本编辑器打开
3) CTRL + G 定位行号 288 或 277 就我而言
4) 或者找到以下函数“ 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)改 edmFunction.Name 至 edmFunction.FullName 这是此函数的倒数第二行并运行您的代码:)
我在 EF5 中遇到了这个问题,希望微软在 future 的 EF 版本中解决这个问题。
关于entity-framework - EntityCommand.CommandText 值的格式必须为 'ContainerName.FunctionImportName',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21241104/