从VS2010升级到VS2012后,Linq到EF加入"索引超出范围"

Erw*_*win 12 .net linq entity-framework exception visual-studio-2012

从Visual Studio 2010升级到2012后,代码开始抛出"ArgumentOutOfRangeException - 索引超出范围.必须是非负的且小于集合的大小.参数名称:索引"在使用联接的Linq查询上.

在LINQPad中使用以下简单示例(使用EF数据模型)给出了ArgumentOutOfRangeException:

void Main()
{
    var iq1 = Customers.Select(ap => ap.ID);
    var iq2 = iq1.Join(Customers.Select(ap => ap.ID),
                    a => a,
                    b => b,
                    (a, b) => new { a });

    iq2.Dump(); 
}
Run Code Online (Sandbox Code Playgroud)

更改前面的示例以返回包含连接两边的匿名对象不会给出ArgumentOutOfRangeException并按预期方式给出结果:

void Main()
{
    var iq1 = ActionPlans.Select(ap => ap.ID);
    var iq2 = iq1.Join(ActionPlans.Select(ap => ap.ID),
                    a => a,
                    b => b,
                    (a, b) => new { a, b });

    iq2.Dump(); 
}
Run Code Online (Sandbox Code Playgroud)

好的,所以由于某种原因我不得不返回连接的两边,但后来我尝试使用虚拟值代替以下示例,也执行没有问题:

void Main()
{
    var iq1 = ActionPlans.Select(ap => ap.ID);
    var iq2 = iq1.Join(ActionPlans.Select(ap => ap.ID),
                    a => a,
                    b => b,
                    (a, b) => new { a, x = 1 });

    iq2.Dump(); 
} 
Run Code Online (Sandbox Code Playgroud)

采用第一个示例并将ToList()添加到第一个查询也使其执行没有问题:

void Main()
{
    var iq1 = ActionPlans.Select(ap => ap.ID).ToList();
    var iq2 = iq1.Join(ActionPlans.Select(ap => ap.ID),
                    a => a,
                    b => b,
                    (a, b) => new { a });

    iq2.Dump(); 
}
Run Code Online (Sandbox Code Playgroud)

重要说明:在没有Visual Studio 2012升级的情况下在工作站上尝试第一个查询工作正常!

任何人都可以确认/解释这个新的"功能"吗?:-)

div*_*ega 6

Erwin,只是为了关闭这个循环:我们已经确认这是我们最近在LINQ to Entities中引入的一个错误,我们正在寻找解决问题的方法.非常感谢报道!