.net - 具有 Entity Framework 的 Sqlite - 错误 : "Specified cast is not valid"

标签 .net vb.net entity-framework sqlite

字段类型是金钱,如果我在字段中输入“0”或“1”,则会收到此错误:

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 ---

这是来自模型设计师的:

<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

获取错误的代码:

 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

最佳答案

我遇到了问题...不是金额字段。另一列是位类型,有时它不喜欢我写假或真的方式。这导致了问题。

解决方案是使用 1 表示 true,0 表示 false,这样总是可以的。

关于.net - 具有 Entity Framework 的 Sqlite - 错误 : "Specified cast is not valid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7013456/

相关文章:

c# - 在 EF 4.3 的 LINQ 查询中使用 "let"关键字

c# - 记录Web服务启动/停止

.net - 本土集成系统还是 ESB?

ASP.NET libwebp.dll 如何将 WebP 图像保存到磁盘

vb.net - vb.net 中的 LINQ 新手问题

c# - Entity Framework 语法与 DBset 混淆

c# - 针对数据库的 EF 模型验证

c# - 循环中委托(delegate)的异步调用

c# - 硬盘 ID 的长度及其解释

mysql - 删除可选查询 datagridview 中的冗余列