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

Error using Average function over System.Int64 field

1 Answer 45 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.
Michael
Top achievements
Rank 1
Michael asked on 23 Aug 2013, 01:09 PM
Here, Age is System.Int64 (long) field. When using Average function over it: 
var query =
 from contact in context.Contacts
 group contact by contact.Name
 into g
 select new { Name = g.Key, AvgAge = g.Average(e => e.Age) };

The following exception occurs:

System.InvalidCastException: Type cast exception: double required, found System.Int64 ---> System.InvalidCastException: Specified cast is not valid.
 at System.Data.SqlClient.SqlBuffer.get_Double()
 at System.Data.SqlClient.SqlDataReader.GetDouble(Int32 i)
 at OpenAccessRuntime.Data.DoubleConverter.Read(DataHolder& data)
 --- End of inner exception stack trace ---
 at OpenAccessRuntime.Data.DoubleConverter.Read(DataHolder& data)
 at OpenAccessRuntime.Relational.fetch.FopGetProjection.fetch(FetchResult fetchResult, StateContainer stateContainer)
 at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)
Processing 1: [0] System.InvalidCastException: Type cast exception: double required, found System.Int64 ---> System.InvalidCastException: Specified cast is not valid.
 at System.Data.SqlClient.SqlBuffer.get_Double()
 at System.Data.SqlClient.SqlDataReader.GetDouble(Int32 i)
 at OpenAccessRuntime.Data.DoubleConverter.Read(DataHolder& data)
 --- End of inner exception stack trace ---
 at OpenAccessRuntime.Data.DoubleConverter.Read(DataHolder& data)
 at OpenAccessRuntime.Relational.fetch.FopGetProjection.fetch(FetchResult fetchResult, StateContainer stateContainer)
 at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)

1 Answer, 1 is accepted

Sort by
0
Accepted
Viktor Zhivkov
Telerik team
answered on 28 Aug 2013, 08:09 AM
Hi Michael,

I am sorry for the inconvenience that you have experienced with this issue.
You are the first to report this bug in our DoubleConverter.
You can expect this issue to be fixed in our next public release of OpenAccess.
Unfortunately I cannot offer you any work around except using a different type for the Age property and database column. Based on the code in the DoubleConverter you should be fine if you use Int32, Decimal or Double.

In recognition of being the first to report new issue I have added a few Telerik points to your account.
I will notify you as soon as a build with the fix is available for download.

Regards,
Viktor Zhivkov
Telerik
OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Tags
Development (API, general questions)
Asked by
Michael
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
Share this question
or