How can i get Entity Framework to recognise columns from dynamic stored procedure
I am using Entity Framework 4 and we have a bunch of stored procedures in our model. Currently we can do everything we need. However we have a new procedure that takes a strin开发者_运维知识库g, and ultimately performs something such as
Create Procedure usp_RunSearch
@searchTerm VARCHAR(2000)
AS
BEGIN
DECLARE @sql VARCHAR(4000)
SET @sql = '
SELECT ID,
NAME
FROM Users'
IF(ISNULL(@searchTerm, '') != '')
BEGIN
SET @sql = @sql + 'WHERE ' + @searchTerm
END
Exec (@sql)
END
to return the result-set.
EF does not seem to be able to interrogate this procedure to get the resultant column list.
Is there anything i can do to help EF get over this hurdle?
If you just want to use it, you can do so. check this link out. http://blogs.msdn.com/b/adonet/archive/2011/02/04/using-dbcontext-in-ef-feature-ctp5-part-10-raw-sql-queries.aspx
Btw, try adding a default value for the stored procedure parameter, that might also work.
Create Procedure usp_RunSearch
@searchTerm VARCHAR(2000) = ''
AS
In the end i have created a ComplexType by hand in the EDMX and setup the function import for the stored procedure to use this manually defined complex type. I think that when EF inspects the sproc it can't figure the return set of columns, even though the select list is relatively static in my example.
精彩评论