"指定的转换是无效的"节能LINQ到SQL实体时错误 [英] "Specified cast is not valid" error when saving LINQ-To-SQL entity
问题描述
软件详情:
C#,ASP.NET MVC中,SQL Server 2008(版本相同&放大器; SP级别),LINQ到SQL ORM
App Details: C#, ASP.NET MVC, SQL Server 2008 ( Same version & SP level), Linq-To-SQL ORM
我试图诊断异常我收到:
I'm trying to diagnose an exception I'm receiving:
指定强制转换是无效的。
在System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManage`2.TryCreateKeyFromValues(Object[]值,V&安培; v)的结果
在System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(对象[]键值)结果
在System.Data.Linq.IdentityManager.StandardIdentityManager.Find(元类型类型,对象[]键值)结果
在System.Data.Linq.CommonDataServices.GetCachedObject(元类型类型,对象[]键值)结果
在System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc命令,对象实例)结果
在System.Data.Linq.ChangeProcessor.BuildEdgeMaps()结果
在System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)结果
在System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)结果
在System.Data.Linq.DataContext.SubmitChanges()结果
在Repository.Save()
在等...
"Specified cast is not valid." at System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManage`2.TryCreateKeyFromValues(Object[] values, V& v)
at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues)
at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
at System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges()
at Repository.Save() at etc....
的问题是,这是发生仅在我们的服务器,而不是在本地发展框。我跟踪它到我们正在修改中的一个属性:
The problem is that this is occurring only on our servers, not on our local development boxes. I've tracked it down to a single property we're modifying:
event.SalesForceId = "701Q0000000AOTIIA4";
如果我注释掉该行,一切工作正常。
If I comment out that line, everything works fine.
我试过:
1)打蜡所有code的服务器和重新部署上。同样的问题。结果
2)拉下Server数据库的副本,并在当地尝试它。工作正常。结果
3)我们尝试对同一个盒子安装另一个IIS环境。同样的问题。结果
4)物理比较(使用AdeptSQL)本地和远程模式。没有差异。结果
5)验证两列(本地和远程的数据类型)是相同的。此外,这列是FK到另一个表。我核实,两者是相同的数据类型,向下整理。
1 ) waxing all of the code on the server and redeploying. Same issue.
2 ) Pulling down a copy of the server DB and trying it locally. Works fine.
3 ) Trying another IIS environment we have setup on the same box. Same issue.
4 ) Physically comparing ( using AdeptSQL ) both local and remote schemas. No differences.
5 ) Verifying the datatypes of both columns ( local and remote ) are the same. Also, this column is a FK to another table. I verified that both are of the same data type, down to the collation.
该服务器是Windows Server 2008和当地的盒子是Windows 7的64位。两者有所有重要更新设置。
The server is Windows Server 2008 and the local box is Windows 7 x64. Both have all important updates setup.
我能想到的唯一的事情也许是因为数据库和Web服务器在不同的箱子,可能是一个问题?否则,我完全难住了。
The only thing I can think of is perhaps since the database and web server are on different boxes that could be an issue? Otherwise, I'm completely stumped.
任何想法?
推荐答案
这是在LINQ一个众所周知的缺陷,以SQL。
This is a well-known bug in LINQ to SQL.
<一个href=\"https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351358\">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351358
有对于问题的修补程序。
There is a hotfix for the issue.
<一个href=\"http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=963657&kbln=en-us\">http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=963657&kbln=en-us
这篇关于&QUOT;指定的转换是无效的&QUOT;节能LINQ到SQL实体时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!