我正在尝试在我的项目中执行存储过程,但枚举没有产生任何结果。
为什么?我究竟做错了什么?
关于我的项目的信息:
.NET Framework 4.5
<package id="EntityFramework" version="5.0.0" targetFramework="net45" />
Microsoft SQL Server 2008 (SP3) - 10.0.5500.0 (X64)
手动使用存储过程可以工作并返回正确的数据:
DECLARE @return_value int
EXEC @return_value = [dbo].[GetFeatures]
@XMLDoc = N'<ArrayOfInt><int>280</int><int>286</int><int>279</int><int>292</int><int>277</int></ArrayOfInt>',
@ReleaseId = 340
SELECT 'Return Value' = @return_value
这是我在代码中执行存储过程的地方:
public ObjectResult<GetFeatures_Result> GetFeatures(List<int> featureIds, int releaseId, int? timeboxId, int? teamId)
{
string xmlFeatureIds = null;
var xs = new XmlSerializer(typeof(List<int>));
var ms = new MemoryStream();
xs.Serialize(ms, featureIds.ToList());
//xmlFeatureIds = Encoding.UTF8.GetString(ms.ToArray());
xmlFeatureIds = "<ArrayOfInt><int>280</int><int>286</int><int>279</int><int>292</int><int>277</int></ArrayOfInt>";
//releaseId = 340;
var release = _rmContext.Releases.FirstOrDefault(x => x.Id == releaseId);//works, Releases is just a table
var obj = _rmContext.GetFeatures(xmlFeatureIds, releaseId, null, null); //enumeration didn't yield any results
var obj2 = _rmContext.GetFeatures(xmlFeatureIds, releaseId, null, null).ToList(); //length of this is zero.
return obj;
}
模型浏览器和视觉工作室设置:
编辑:
从 SQL 探查器:
declare @p1 xml
set @p1=convert(xml,N'<ArrayOfInt><int>280</int><int>286</int><int>279</int><int>292</int><int>277</int></ArrayOfInt>')
exec [dbo].[GetFeatures] @XMLDoc=@p1,@ReleaseId=340,@TimeBoxId=NULL,@TeamId=NULL