DbContext生成器和存储过程

时间:2012-01-25 18:46:01

标签: stored-procedures entity-framework-4 database-first

注意:我正在使用带有数据库优先方法和DbContext的EF 4.2。这首先是 NOT 代码。

我正在尝试使用DbContext t4 tempalate来生成Stored Proc方法。似乎内置了它的功能(它映射到基础ObjectContext),但由于某种原因它固执地拒绝生成它们。我认为它可能与返回类型(单个int,而不是模型类型)有关,但我不确定。

在有人说之前。是的,我知道DbContext不支持存储过程,这就是t4模板使用IObjectContextAdapter将其转换为ObjectContext的原因。这是内置功能。<​​/ p>

过去,这些方法只是自动生成的。我不知道为什么现在不行。该函数出现在.edmx文件中。关于如何解决这个问题的任何建议?

<Function Name="pInsertMemberPayment" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">
  <Parameter Name="xMemberID" Type="int" Mode="In" />
  <Parameter Name="xCardHolderName" Type="varchar" Mode="In" />
  <Parameter Name="xBillingAddress" Type="varchar" Mode="In" />
  <Parameter Name="xBillingCity" Type="varchar" Mode="In" />
  <Parameter Name="xBillingState" Type="char" Mode="In" />
  <Parameter Name="xBillingZip" Type="varchar" Mode="In" />
  <Parameter Name="xAccountNumber" Type="varchar" Mode="In" />
  <Parameter Name="xExpirationDate" Type="date" Mode="In" />
  <Parameter Name="xRowCreatedSYSUserID" Type="int" Mode="In" />
  <Parameter Name="xRowCreatedDateTime" Type="datetime2" Mode="In" />
  <Parameter Name="xRowModifiedSYSUserID" Type="int" Mode="In" />
  <Parameter Name="xRowModifiedDateTime" Type="datetime2" Mode="In" />
  <Parameter Name="xMemberPaymentID" Type="int" Mode="InOut" />
</Function>

1 个答案:

答案 0 :(得分:3)

您的示例函数在SSDL中显示存储过程定义,但它不显示CSDL中的函数导入或MSL中的函数导入映射。您是否在模型浏览器中为存储过程创建了函数导入?我刚刚使用10个不同的过程测试了DbContext Generator模板,返回实体,复杂类型,标量并使用输入和输出参数,并在每个上下文类中生成方法(但它们必须映射到函数导入)。