为什么我看不到我的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">
类似的问题是:
Why won't EF4 generate a method to support my Function Import?
但我做了所有的建议。
这是存储过程:
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
我缺少什么?
由于
答案 0 :(得分:5)
DbContext不支持将存储过程映射到方法。您必须使用context.Database.SqlCommand(...)或context.Database.SqlQuery(...)直接调用过程