我试图使用以下SQL存储过程根据输入参数获取SQL表中的值列表作为输出。
CREATE PROCEDURE GetFirstNames
@LastName nvarchar(128),
@FirstNames nvarchar(128) OUTPUT
AS
SET @FirstNames = (SELECT FirstName FROM NamesTable WHERE LastName = @LastName)
GO
我使用以下代码从表中获取名字列表。
SqlParameter lastNameParam = new SqlParameter("@LastName", "Smith");
SqlParameter firstNamesParameter = new SqlParameter("@FirstNames", SqlDbType.NVarChar, 128);
firstNamesParameter.Direction = ParameterDirection.Output;
string sql = String.Format("EXEC dbo.GetFirstNames {0}, {1};",
lastNameParam.ParameterName,
firstNamesParameter.ParameterName);
context.Database.ExecuteSqlCommand(sql, lastNameParam, firstNamesParameter);
当我调用ExecuteSqlCommand方法时,我收到以下错误:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
如果有人可以帮助我,我真的很感激。 感谢。
答案 0 :(得分:2)
string json = ""; //your json string.
SampleClass[] arr = JsonConvert.DeserializeObject<SampleClass[]>(json);
foreach (SampleClass obj in arr)
{
obj.IDAlokasiEmiten = 0;
obj.IDOrganization = 12;
}
将修复查询部分并为您提供可枚举的结果集。其余的是OP的练习。