Click here to Skip to main content
14,454,012 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
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);
        }



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 ...
Posted
Updated 27-Dec-13 2:04am
v2
Comments
AlexDpars 27-Dec-13 10:09am
   
What is your .Net Framework version? What is your EF version also ( it will be write when you add the EDMX file to your project )
Vi(ky 28-Dec-13 6:56am
   
.Net framework version is 4.5 & Entity Framework version is 5.0
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Comments
Vi(ky 28-Dec-13 6:55am
   
yes, the function name is in the list of Function Import list
Christian Graus 28-Dec-13 14:25pm
   
And it shows up with autocomplete ? If so, then I think you just need to refresh your whole model, as I said.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Use trivial ADO.NET Connections and pass the stored procedure name. This will work.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Check this sample application:

Entity Framework for Beginners[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100