Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite with Entity framework - Error: "Specified cast is not valid"

The field type is money, if I put a '0' or a '1' in the field I get this error:

System.Reflection.TargetInvocationException:

Exception has been thrown by the target of an invocation. --->
System.InvalidCastException: Specified cast is not valid.

 at System.Data.SQLite.SQLiteDataReader.VerifyType(Int32 i, DbType typ)
 at System.Data.SQLite.SQLiteDataReader.GetBoolean(Int32 i)

 --- End of inner exception stack trace ---

This is from the model designer:

<Property Name="Amount" Type="decimal" Precision="53" />  

====

    <EdmScalarPropertyAttribute(EntityKeyProperty:=False, IsNullable:=True)>
<DataMemberAttribute()>
Public Property Amount() As Nullable(Of Global.System.Decimal)
    Get
        Return _Amount
    End Get
    Set(ByVal value As Nullable(Of Global.System.Decimal))
        OnAmountChanging(Value)
        ReportPropertyChanging("Amount")
        _Amount = StructuralObject.SetValidValue(value)
        ReportPropertyChanged("Amount")
        OnAmountChanged()
    End Set
End Property

Private _Amount As Nullable(Of Global.System.Decimal)
Private Partial Sub OnAmountChanging(value As Nullable(Of Global.System.Decimal))
End Sub

Private Partial Sub OnAmountChanged()
End Sub

Code to get error:

 Dim Query = From c In EnData.Transactions Where c.TranID = 660 ' this tran is the amount 0

        For Each tran In Query 'Error here

        Next
like image 571
Ezi Avatar asked Apr 25 '26 18:04

Ezi


1 Answers

I Got the problem... its not the amount field. an other column which is a bit type, some times it doesn't like the way I wrote the false or true. that causes the problem.

The solution is to use 1 for true and 0 for false, that is always ok.

like image 165
Ezi Avatar answered Apr 27 '26 06:04

Ezi