1

注意:我将 EF 4.2 与 Database First Method 和 DbContext 一起使用。这不是代码优先。

我正在尝试获取 DbContext t4 模板来生成存储过程方法。它似乎内置了这样做的功能(它映射到基本 ObjectContext),但由于某种原因它顽固地拒绝生成它们。我认为它可能与返回类型(它是单个 int,而不是模型类型)有关,但我不确定。

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

过去,这些方法只是自动生成的。我不知道为什么不是现在。函数出现在 .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>
4

1 回答 1

3

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

于 2012-01-25T20:08:05.110 回答