使用ADO.NET Entity Framework存储过程

时间:2021-08-06 02:17:40

I'm trying to use a stored procedure in the entity framework. I had the model created initially without the stored proc. I then went into Update Model from Database and selected the stored procedure I wanted and then added it through the function import. Now I can see the function in the model browser under Function Imports but when I try to call it on the object context I get the error saying 'xxModel' does not contain a definition for 'xxfunction'. Any idea what I could be doing wrong?

我正在尝试在实体框架中使用存储过程。我最初创建的模型没有存储过程。然后我从数据库进入更新模型并选择我想要的存储过程,然后通过函数import添加它。现在我可以在Function Imports下的模型浏览器中看到该函数,但是当我尝试在对象上下文中调用它时,我得到的错误是'xxModel'不包含'xxfunction'的定义。知道我可能做错了吗?

I don't see any errors in the file related to the proc.

我没有看到与proc相关的文件中的任何错误。

Here are the tags for the stored procs in the edmx file

以下是edmx文件中存储过程的标记

    <Function Name="p_DeleteDealFacts" Aggregate="false" BuiltIn="false"
        NiladicFunction="false" IsComposable="false"
        ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
        <Parameter Name="DealID" Type="int" Mode="In" />

    <FunctionImportMapping FunctionImportName="DeleteDealFacts"
          FunctionName="InterceptModel.Store.p_DeleteDealFacts" />
</EntityContainerMapping>

2 个解决方案

#1


Visual Studio generates the function code in the model's code-behind if and only if you specify the return to be an entity type. Scalar and null return types do not work. Looks like a bug to me. Here is the full story: Function Imports in Entity Model with a non-Entity Return Type

当且仅当您将返回指定为实体类型时,Visual Studio才会在模型的代码隐藏中生成函数代码。标量和null返回类型不起作用。对我来说看起来像个错误。以下是完整的故事:具有非实体返回类型的实体模型中的函数导入

#2


Open your Entity Data Model in XML view and check to see if you have any

在XML视图中打开您的实体数据模型,并检查您是否有任何数据模型

<!--Errors Found During Generation: warning XXXX: The table/view/stored proc .....MDF.dbo.StoredProcName' does not have .... -->

Tags

If you don't then search for your <Function Name="{Name}" /> tags, and also do a search for that {Name}. Check to make sure nothing seems out of place.

如果不这样做,则搜索 标签,并搜索{Name}。检查以确保没有任何不合适的地方。

If you can't find any problems, post those tags and your store procedure in your question.

如果您找不到任何问题,请在您的问题中发布这些标签和商店程序。

#1


Visual Studio generates the function code in the model's code-behind if and only if you specify the return to be an entity type. Scalar and null return types do not work. Looks like a bug to me. Here is the full story: Function Imports in Entity Model with a non-Entity Return Type

当且仅当您将返回指定为实体类型时,Visual Studio才会在模型的代码隐藏中生成函数代码。标量和null返回类型不起作用。对我来说看起来像个错误。以下是完整的故事:具有非实体返回类型的实体模型中的函数导入

#2


Open your Entity Data Model in XML view and check to see if you have any

在XML视图中打开您的实体数据模型,并检查您是否有任何数据模型

<!--Errors Found During Generation: warning XXXX: The table/view/stored proc .....MDF.dbo.StoredProcName' does not have .... -->

Tags

If you don't then search for your <Function Name="{Name}" /> tags, and also do a search for that {Name}. Check to make sure nothing seems out of place.

如果不这样做,则搜索 标签,并搜索{Name}。检查以确保没有任何不合适的地方。

If you can't find any problems, post those tags and your store procedure in your question.

如果您找不到任何问题,请在您的问题中发布这些标签和商店程序。