Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What may be wrong here?
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Titre:
What may be wrong here?
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01610844
Message ID:
01610844
Vues:
33
UPDATE. Adding ToList() before attempting to access the output parameter solved the problem. For the reference

http://stackoverflow.com/questions/11781771/executestorequery-output-parameter-not-being-returned?rq=1

Hi everybody,

I am trying to execute a stored procedure using the following code (using Entity Framework):
  IEnumerable<InvoicesList> result = new List<InvoicesList>();
            SqlParameter par1 = new SqlParameter("@acctName", SqlDbType.Char, 10);
            par1.Value = accountName;
            SqlParameter par2 = new SqlParameter("@Finalized", SqlDbType.Bit);
            par2.Value = showFinalized;

            SqlParameter par3 = new SqlParameter("@PageSize", SqlDbType.Int);
            par3.Value = queryRequest.PageSize;

            SqlParameter par4 = new SqlParameter("@PageNumber", SqlDbType.Int);
            par4.Value = queryRequest.Page;

            SqlParameter par5 = new SqlParameter("@SearchText", SqlDbType.VarChar, -1);
            par5.Value = searchText??"";

            SqlParameter par6 = new SqlParameter("@OrderByColumn", SqlDbType.VarChar, 20);
            par6.Value = queryRequest.OrderBy;

            SqlParameter par7 = new SqlParameter("@SortOrder", SqlDbType.VarChar, 4);
            par7.Value = queryRequest.Dir;

            SqlParameter par8 = new SqlParameter("@TotalRows", SqlDbType.Int);
            par8.Direction = ParameterDirection.Output;            

            result = _siriusContext.CoreContext.ExecuteStoreQuery<InvoicesList>(@"execute dbo.siriussp_GetAccountInvoicesWithPaging @acctName = @acctName, @Finalized = @Finalized,
@PageSize = @PageSize, @PageNumber = @PageNumber, @SearchText = @SearchText, @OrderByColumn = @OrderByColumn, @SortOrder = @SortOrder, 
@TotalRows = @TotalRows OUTPUT",
    par1, par2, par3, par4, par5, par6, par7, par8);
            Int32 count = (Int32)par8.Value;
The error seems to occur on the very last line Int32 count when I try to get value of my output parameter.

I can see using SQL Profiler that the executed query seems to be OK (and it works):
declare @p10 int
set @p10=23
exec sp_executesql N'execute dbo.siriussp_GetAccountInvoicesWithPaging @acctName = @acctName, @Finalized = @Finalized,
@PageSize = @PageSize, @PageNumber = @PageNumber, @SearchText = @SearchText, @OrderByColumn = @OrderByColumn, @SortOrder = @SortOrder, 
@TotalRows = @TotalRows OUTPUT',N'@acctName char(10),@Finalized bit,@PageSize int,@PageNumber int,@SearchText varchar(max) ,@OrderByColumn varchar(20),@SortOrder varchar(4),@TotalRows int output',@acctName='*RESRVATN*',@Finalized=0,@PageSize=15,@PageNumber=1,@SearchText='',@OrderByColumn='InvoiceNo',@SortOrder='Asc',@TotalRows=@p10 output
select @p10
I am not sure why I am getting set @p10 = 23 (this is the result of the query) and how can I get that value back. Also, I need result of the procedure to be returned as enumerable list.

I do not go into the ExecuteStoreQuery method even though I try to debug (it's EF method and doesn't let me see its code).

Do you see what I may be doing wrong here?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Répondre
Fil
Voir

Click here to load this message in the networking platform