我在使用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内部。