CodeSmith Community
Your Code. Your Way. Faster!

database field defined as float causing invalid cast exception

Latest post 06-25-2007 3:06 PM by swin. 1 replies.
  • 05-22-2007 9:51 AM

    • millerwa
    • Top 500 Contributor
    • Joined on 05-03-2007
    • Posts 18
    • Points 465

    database field defined as float causing invalid cast exception

    I have a couple of fields in the database designated as floats.

     In the mapping config file they get defined as follows:

    <Column Id="Field1" CSType="System.Double?" PropertyName="Field1" FieldName="Field1" FriendlyName="Field1" IncludeInOutput="true" />

    <Column Id="Field2" CSType="System.Double?" PropertyName="Field2" FieldName="Field2" FriendlyName="Field2" IncludeInOutput="true" />

     However when the code gets generated they are casting as Decimal and the property is a decimal as well

     entity.Field1= reader.IsDBNull(reader.GetOrdinal("Field1")) ? null : (System.Decimal?)reader["Field1"];

     at this point I get the error "Specified cast is not valid."

    So how come the entity is using a decimal when it should probably be using a System.Double?

     

    • Post Points: 35
  • 06-25-2007 3:06 PM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: database field defined as float causing invalid cast exception

    What version are you using - the latest SVN580 version seems to be ok on this point.

    hth

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems