FOR JSON
will return a single record with a single
nvarchar(max)
field containing the JSON-formatted results of the query.
string json = string.Concat(entities.Database.SqlQuery("exec usp_getjsondata @type",
new SqlParameter("@type", type)
));
If you want to convert that back to a list of objects, then you'll need to parse the JSON:
var results = JsonConvert.DeserializeObject<IList<YourClass>>(json);
However, if you're doing that, then it would be better to remove the
FOR JSON
from the query, and load the results directly into the list:
var results = entities.Database.SqlQuery<YourClass>("exec usp_getdata @type",
new SqlParameter("@type", type)
).ToList();
Use FOR JSON output in SQL Server and in client apps (SQL Server) | Microsoft Docs[
^]