3

为什么我看不到在我的 DbContext 中添加的存储过程?DbContext 由随 CTP5 版本(带有 POCO 类)引入的模板生成。

我添加了本教程所述的存储过程:http: //thedatafarm.com/blog/data-access/checking-out-one-of-the-new-stored-procedure-features-in-ef4/

此外,我搜索了是否在我的上下文中添加了条目,结果如下:

<Function Name="GetClientsForEmailSend" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" />

<FunctionImport Name="GetClientsForEmailSend" EntitySet="Client" ReturnType="Collection(DBMailMarketingModel.Client)" />

<FunctionImportMapping FunctionImportName="GetClientsForEmailSend" FunctionName="DBMailMarketingModel.Store.GetClientsForEmailSend">

一个类似的问题是:

为什么 EF4 不生成支持我的函数导入的方法?

但我已经做了所有的建议。

这是存储过程:

ALTER PROCEDURE GetClientsForEmailSend
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT OFF;

-- Insert statements for procedure here
SELECT *
FROM dbo.Client AS c
INNER JOIN Subscription AS i on c.IDClient = i.IDClient
WHERE c.Email is not null and c.Email <> '' and i.Active = 1
END
GO

我错过了什么?

谢谢

4

1 回答 1

5

DbContext 不支持将存储过程映射到方法。您必须使用 context.Database.SqlCommand(...) 或 context.Database.SqlQuery(...) 直接调用过程

于 2011-02-18T15:15:33.027 回答