Oracle专栏:user_id int not null,
Linq查询:
UserId = user.Field<int>("user_id"),
UserId是int类型。其他字符串,char字段工作正常,只有当我使用thsi字段时才会收到此错误。
正确的映射是什么,或者我做错了什么?
答案 0 :(得分:2)
如果您使用的是Field<T>()
,则表明您使用的是DataTable
,此时数据库类型大多无关紧要。该异常应该向您展示演员表是如何失败的 - 实际类型是什么。如果没有,您可以轻松地进行一些诊断:
object o = user["user_id"];
if (o == null)
{
Console.WriteLine("user_id is null");
}
else
{
Console.WriteLine("Actual type of user_id: {0}", o.GetType());
}
我怀疑你会发现它是long
或short
,或类似的东西 - 但这应该会向你展示。