EntityFrameworkCode-Firstのストアドプロシージャを介してエンティティを具体化しています。ストアドプロシージャはintパラメータを受け取り、選択したレコードといくつかの出力パラメータの両方を出力します。何らかの理由で、SQL Management StudioからProcを実行しているときに、出力パラメーターでNullが返され、期待どおりの動作が得られます。すべての出力パラメーターには値があります。私の実体は具体化されているので、少なくともそれは機能しています...
EFコード
SqlParameter DocsWithHits = new SqlParameter()
{
ParameterName = "DocumentsWithHits",
Direction = System.Data.ParameterDirection.Output,
Value = null,
SqlDbType = System.Data.SqlDbType.Int
};
SqlParameter TotalGB = new SqlParameter()
{
ParameterName = "TotalGb",
Direction = System.Data.ParameterDirection.Output,
Value = null,
SqlDbType = System.Data.SqlDbType.Float
};
ObservableCollection<SearchResult> ResultCollection;
ResultCollection = new ObservableCollection<SearchResult>(db.Database.SqlQuery<SearchResult>(
"exec ListSearchResultsWithTotals @SearchAnalysisID, @DocumentsWithHits, @RelatedDocuments, @TotalDocuments, @TotalGb, @DocumentsWithHitsNotExported, @RelatedDocumentsNotExported, @TotalDocumentsNotExported, @TotalGbNotExported",
new SqlParameter
{
ParameterName = "SearchAnalysisID",
Value = this.SearchAnalysisId
},
DocsWithHits,
TotalGB));
SQLプロファイラー
SqlQueryメソッドから生成されるSQLは以下のとおりです。プロファイラーでキャプチャしました。実行すると、レコードとnull出力パラメーターを取得します。
declare @p4 int
set @p4=NULL
declare @p5 float
exec sp_executesql N'exec ListSearchResultsWithTotals @SearchAnalysisID, @DocumentsWithHits, @TotalGb',N'@SearchAnalysisID int,@DocumentsWithHits int output,@TotalGb float output',@SearchAnalysisID=170,@DocumentsWithHits=@p4 output,@TotalGb=@p5 output
select @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11
SqlParameterを間違って使用していますか?