为什么Linq to Entity Select Method翻转投影列表属性?

Wil*_*lFM 16 c# asp.net-mvc linq-to-entities json entity-framework

我对linq to entity/Json/MVC.net 4有最奇怪的行为

我有这些代码,并且由于一些奇怪的原因,每个其他列表的属性顺序都是相反的.

var output = db.FooBar.Where(a => a.lookupFoo == bar)
                      .Select(a => new List<double>{
                                     //value's are the same per row 
                                     //for demonstration sake.
                          a.fooBarA,  //Always 12.34
                          a.fooBarB,  //Always 12.34
                          a.fooBarC,  //Always 0
                          a.fooBarD  //Always 0 //lazy casting to double from int
                      });
return Json(new {output});
Run Code Online (Sandbox Code Playgroud)

输出看起来像这样:

{
  "output": [
    [12.34, 12.34, 0,     0], 
    [0,     0,     12.34, 12.34], 
    [12.34, 12.34, 0,     0],
    [0,     0,     12.34, 12.34]
  ]
};
Run Code Online (Sandbox Code Playgroud)

我已经设法通过toList()在Where和Select之间放置一个来解决它,但我仍然想知道为什么会发生这种情况.

更多信息:EF 4.4(tt生成的上下文),SQL Server 2008r2表达.NET 4.0,MVC 3.0,Vanilla System.Web.Mvc.JsonResult,表由一个int主键组成,浮点数除去最后一个是int的值

小智 1

尝试

var output = db.FooBar.Where(a => a.lookupFoo == bar)
                  .Select(a => new List<double>{
                                 //value's are the same per row 
                                 //for demonstration sake.
                      a.fooBarA,  //Always 12.34
                      a.fooBarB,  //Always 12.34
                      a.fooBarC,  //Always 0
                      a.fooBarD  //Always 0 //lazy casting to double from int
                  }).toList();
return Json(output);
Run Code Online (Sandbox Code Playgroud)

在您的输出方式中,仅上下文生成的用于获取数据的脚本可能是在大小 Json() 中执行多次