字段类型是金钱,如果我在字段中输入“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/