How to get dynamic SQL result from SP in entity framework?

Posted by KentZhou on Stack Overflow See other posts from Stack Overflow or by KentZhou
Published on 2010-06-16T14:05:19Z Indexed on 2010/06/16 14:12 UTC
Read the original article Hit count: 293

Filed under:

Suppose I have following SP to run a dynamic sql ALTER PROCEDURE [dbo].[MySP] AS BEGIN

declare @sql varchar(4000)
select @sql = 'select cnt = count(*) from Mytable ..... ';
exec (@sql)

END

then in edmx, I add the sp and import function for this sp. the return type is scalars int32.

then I want to use this function in code like:

int? result = context.MySP();

I got error said "cannot implicitly convert type System.Data.Objects.ObjectResults to int?"

If use

   var result = context.MySP();

then Single() cann't be applied to context.MySP().

How to get the result for this case?

© Stack Overflow or respective owner

Related posts about entity-framework