InvalidOperationException when casting to array

3 posts, 0 answers
  1. Rob Hedgpeth
    Rob Hedgpeth avatar
    7 posts
    Member since:
    May 2011

    Posted 01 Jun 2011 Link to this post


    I'm getting an "InvalidOperationException" thrown when attempting to execute the following:

    var items = new ServiceObject(unitOfWork).SelectAll()
                  .GroupBy(i => new { i.Value1, i.Value2 })
                  .Select(i => new ViewModelObject(i.Key.Value1, i.Key.Value2))
                  .ToArray();

    The exception details that "Only 2 of 3 projection result columns used." 

    However, if I just attempt to load my "ViewModelObject" with just one value I have no issues.

    var items = new ServiceObject(unitOfWork).SelectAll()
                  .GroupBy(i => new { i.Value1, i.Value2 })
                  .Select(i => new ViewModelObject(i.Key.Value1))
                  .ToArray();

    I'm probably missing something pretty obvious here, but am having a tough time debugging.

    Thanks!
  2. Rob Hedgpeth
    Rob Hedgpeth avatar
    7 posts
    Member since:
    May 2011

    Posted 01 Jun 2011 Link to this post

    I was able to get past the exception by modifying my code to the following:

    var items = new ServiceObject(unitOfWork).SelectAll()
                  .GroupBy(i => new { i.Value1, i.Value2 })
                  .Select(i => new { j.Key })
                  .Select(i => new ViewModelObject(i.Key.Value1, i.Key.Value2))
                  .ToArray();

    However, I'm not sure why this had made any difference.
  3. DevCraft banner
  4. Serge
    Admin
    Serge avatar
    375 posts

    Posted 06 Jun 2011 Link to this post

    Hi Rob Hedgpeth,

     I am sorry for not being helpful but as far as I can see the ServiceObject class and the LINQ implementation are not part of anything Telerik related, not to mention OpenAccess related.

    Would you mind giving a little more details as to what the problem is and how it is related with OpenAccess. What are you trying to achieve and how. 

    I am looking forward to resolving this issue, please get back to us with a little more information.

    Greetings,
    Serge
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Back to Top