【发布时间】:2015-09-21 19:20:28
【问题描述】:
尝试使用实体框架检索数据时,我不断收到以下错误消息 并分配给我的自定义类 Customer
无法将源类型“system.nullable”转换为目标类型“int”
CustomerNumber 和 Route 的数据类型为 Int32,数据库中的字段允许为空
select new Customer()
{
AccountListId = j.cost1,
Csr = j.cost2,
CustomerName = j.cost3,
Address = j.cost4,
Telephone = j.cost5,
Contact = j.cost6,
CustomerNumber = j.cost7,
Branch = j.cost8,
Route = j.cost9,
}).ToList<Customer>();
我该如何处理?
【问题讨论】:
-
如果数据库中的值为
null,您想为Int32字段分配什么。显然,null无效。你想设置0还是-1,还是什么?
标签: c# linq entity-framework-5