Linq to EF Join throws “Index was out of range” after upgrade from VS2010 to VS2012

后端 未结 2 554
余生分开走
余生分开走 2021-02-14 00:19

After upgrading from Visual Studio 2010 to 2012 code started throwing \"ArgumentOutOfRangeException - Index was out of range. Must be non-negative and less than the size of the

相关标签:
2条回答
  • 2021-02-14 00:46

    After giving this some more investigation, I've come to the conclusion that the problem is the anonymous class I'm returning from the Linq query, I think it isn't allowed anymore to return an anonymous class with only one field in it, I know it isn't needed to wrap the field in an anonymous class but ... as I said this worked before upgrading.

    Following example gives me the "ArgumentOutOfRangeException - Index was out of range":

    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();
    }
    

    this next example works as expected:

    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) => a );
    
        iq2.Dump();
    }
    
    0 讨论(0)
  • 2021-02-14 00:51

    Erwin, just to close the loop on this: We have confirmed that it is a bug we introduced recently in LINQ to Entities and we are looking at ways to get a fix out. Thanks a lot for reporting it!

    0 讨论(0)
提交回复
热议问题