Error using Average function over System.Int64 field

2 posts, 1 answers
  1. Michael
    Michael avatar
    1 posts
    Member since:
    Mar 2008

    Posted 23 Aug 2013 Link to this post

    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)
  2. Answer
    Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 28 Aug 2013 Link to this post

    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.
  3. DevCraft banner
Back to Top