我使用LINQ to SQL抛出了无效的强制转换异常。这是我在C#中的课程:
[Table(Name = "tbl_request$")]
public class request
{
[Column(IsPrimaryKey = true)]
public float requestID;
[Column]
public string moduleCode;
[Column]
public float park;
[Column]
public string requestedRoom;
[Column]
public float week;
[Column]
public float day;
[Column]
public float period;
[Column]
public float status;
[Column]
public float semester;
[Column]
public float priority;
[Column]
public float adhoc;
[Column]
public float numStudents;
[Column]
public float collectionID;
[Column]
public float roomCount;
}
数据库表格对应
requestID float Unchecked
moduleCode nvarchar(255) Checked
park float Checked
requestedRoom nvarchar(255) Checked
week float Checked
day float Checked
period float Checked
status float Checked
semester float Checked
priority float Checked
adhoc float Checked
numStudents float Checked
collectionID float Checked
roomCount float Checked
一切看起来都不错。还有其他建议吗?
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 12: var bookingtable = Database.DatabaseContext.GetTable<Database.request>();
Line 13: var dict = new System.Collections.Generic.Dictionary<int, System.Collections.Generic.List<Database.request>>();
Line 14: foreach (var request in bookingtable)
Line 15: {
Line 16: if (dict[(int)request.collectionID] == null)
堆栈跟踪深入LINQ内部。
答案 0 :(得分:5)
事实证明,即使数据库类型为double?
,C#也需要float?
而不是FLOAT
。