0

嘿伙计们,我想在实体框架中执行这个 SQL 脚本并以JSONResult格式返回结果以在 jQuery 中访问。请帮助!!!

我的实体框架模型包含 SQL 脚本中提到的表和数据库

谢谢 :-)

DECLARE @listCol VARCHAR(2000)
DECLARE @query VARCHAR(4000)
SELECT  @listCol = STUFF(( SELECT distinct  '], [' + [PSize]
                           FROM     Pattern
                         FOR
                           XML PATH('')
                         ), 1, 2, '') + ']'
SET @query = 'SELECT * FROM
      (SELECT PColour as Colour_Size_Matrix, PSize, PCode
            FROM Pattern
            ) src
PIVOT (Count(PCode) FOR PSize
IN (' + @listCol + ')) AS pvt'
EXECUTE ( @query )
4

1 回答 1

0

您需要在模型列表中获取查询结果并像 Json 一样返回:

var context = new YourContext(); 
var results = (from c in context.PCoulor select c).Contains(yourValue).ToList();
return Json(results , JsonRequestBehavior.AllowGet);
于 2012-11-05T10:38:40.047 回答