使用实体框架执行存储过程 [英] Execute Stored Procedure using Entity framework

查看:93
本文介绍了使用实体框架执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用实体框架执行此程序



I want to execute this Procedure using entity framework

/****** Object:  StoredProcedure [dbo].[ProjectTableRowCount]    Script Date: 12/27/2013 16:23:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[ProjectTableRowCount]
( 
	@ProjectId int,
	@SearchKey varchar(50) ,
	@PageNo int , 									
	@PazeSize int 
)
AS
BEGIN

SELECT  AllTableInfo.Id , AllTableInfo.tableName ,AllTableInfo.[rowCount] ,  AllTableInfo.isActive    FROM
( SELECT [Table].Id, TABLE_INFO.*, [Table].isActive,  ROW_NUMBER() OVER(ORDER BY [Table].isActive) AS rownumber FROM [Table]  
INNER JOIN  
(
SELECT      A.Name 'tableName', SUM(B.rows) AS 'rowCount'
FROM        sys.objects A
INNER JOIN  sys.partitions B ON A.object_id = B.object_id
WHERE       A.type = 'U' 
GROUP BY    A.schema_id, A.Name
) AS TABLE_INFO

ON  [Table].tableName = TABLE_INFO.tableName ) AS AllTableInfo
INNER JOIN ProjectTable	ON
ProjectTable.tablesId = AllTableInfo.Id
WHERE ProjectTable.ProjectId = @ProjectId 
AND AllTableInfo.tableName LIKE '%'+@SearchKey +'%'           
AND rownumber > (( @PageNo -1) * @PazeSize )
                         AND rownumber <= ((@PageNo - 1)* @PazeSize)+ @PazeSize

END





我的实体代码





my Entity code

public virtual ObjectResult<ProjectTableRowCount_Result> ProjectTableRowCount(Nullable<int> projectId, string searchKey, Nullable<int> pAGENO, Nullable<int> pazeSize)
        {
            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("projectId", projectId) :
                new ObjectParameter("projectId", typeof(int));
    
            var searchKeyParameter = searchKey != null ?
                new ObjectParameter("SearchKey", searchKey) :
                new ObjectParameter("SearchKey", typeof(string));
    
            var pAGENOParameter = pAGENO.HasValue ?
                new ObjectParameter("PAGENO", pAGENO) :
                new ObjectParameter("PAGENO", typeof(int));
    
            var pazeSizeParameter = pazeSize.HasValue ?
                new ObjectParameter("PazeSize", pazeSize) :
                new ObjectParameter("PazeSize", typeof(int));
    
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ProjectTableRowCount_Result>("ProjectTableRowCount", projectIdParameter, searchKeyParameter, pAGENOParameter, pazeSizeParameter);
        }







但错误是



在容器中找不到函数导入





我通过信息添加函数import给予

http://msdn.microsoft.com/en-us/library/bb896231.aspx



请帮忙......




But the error is

"The function import could not be found in the container"


I add the function import by the information given on
http://msdn.microsoft.com/en-us/library/bb896231.aspx

Please help ...

推荐答案

自动完成功能是否找到您的功能名称?你能在导入的功能列表中看到它吗?如果可以,请尝试刷新数据库中的实体。
Does autocomplete find your function name ? Can you see it in the list of imported functions ? If you can, try refreshing the entities from the database.


使用简单的 ADO.NET Connections 并传递存储过程名称。这将有效。
Use trivial ADO.NET Connections and pass the stored procedure name. This will work.


检查此示例应用程序:



初学者实体框架 [ ^ ]
Check this sample application:

Entity Framework for Beginners[^]


这篇关于使用实体框架执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆