实体框架组通过导致无法施放类型的对象。键入System.String'
我正在尝试遵循EF查询并在数据库的某些情况下返回例外,
//Contacts Stats summary
Dictionary<ContactStatusEnum, int> contactStats = (await context.Contacts.ToListAsync())
.GroupBy(n => n.Status)
.ToDictionary(x => x.Key, x => x.Count());
这导致了异常 异常:无法将“ system.dbnull”类型的对象施放到type“ system.string”。
同时,我执行了SQL
SELECT status,COUNT(*) FROM contacts group BY STATUS
,并在没有任何错误的情况下被执行。另外,所有联系记录都存在状态价值,
同一代码在舞台或开发数据库中工作
I am trying to run following EF query and return the exception on some instances of Databases
//Contacts Stats summary
Dictionary<ContactStatusEnum, int> contactStats = (await context.Contacts.ToListAsync())
.GroupBy(n => n.Status)
.ToDictionary(x => x.Key, x => x.Count());
This is causing an exception
Exception:Unable to cast object of type 'System.DBNull' to type 'System.String'.
At same time i executed sql
SELECT status,COUNT(*) FROM contacts group BY STATUS
and is getting executed without any errors. Plus there are status value exists for all contact records
The same code is working agaist the stage or DEV db
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按照下面的方式进行修改
,请按照此操作
you can modify as below
else follow this one