This is a migrated thread and some comments may be shown as answers.

InvalidOperationException when casting to array

2 Answers 52 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rob Hedgpeth
Top achievements
Rank 2
Rob Hedgpeth asked on 01 Jun 2011, 04:29 PM

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 Answers, 1 is accepted

Sort by
0
Rob Hedgpeth
Top achievements
Rank 2
answered on 01 Jun 2011, 04:49 PM
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.
0
Serge
Telerik team
answered on 06 Jun 2011, 01:20 PM
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.
Tags
Development (API, general questions)
Asked by
Rob Hedgpeth
Top achievements
Rank 2
Answers by
Rob Hedgpeth
Top achievements
Rank 2
Serge
Telerik team
Share this question
or