【发布时间】:2011-08-10 15:29:15
【问题描述】:
字段类型是钱,如果我在字段中输入“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
【问题讨论】:
-
我添加了一些代码,这是您要找的吗?
-
你能告诉我们你设置金额的代码吗?
-
我还没有设置它。我只是通过执行一个简单的查询“Dim Q = (From e in myContext.Transaction)”得到错误
-
@Ezi 显示发生错误的部分代码,以及与该部分相关的所有代码。
-
你确定'Amount'字段是sqlite数据库中的十进制类型吗?如果您在金额字段中存储“2”或“42”,您的代码是否有效?
标签: .net vb.net entity-framework sqlite