调试LINQ to SQL SubmitChanges() [英] Debugging LINQ to SQL SubmitChanges()

查看:142
本文介绍了调试LINQ to SQL SubmitChanges()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力尝试调试LINQ to SQL并提交更改。

I am having a really hard time attempting to debug LINQ to SQL and submitting changes.

我一直在使用 http://weblogs.asp.net/scottgu/archive/2007/07/ 31 / linq-to-sql-debug-visualizer.aspx ,它非常适合调试简单的查询。

I have been using http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx, which works great for debugging simple queries.

我正在DataContext类中工作我的项目与我的应用程序中的以下代码段:

I'm working in the DataContext Class for my project with the following snippet from my application:

JobMaster newJobToCreate = new JobMaster();
newJobToCreate.JobID = 9999
newJobToCreate.ProjectID = "New Project";
this.UpdateJobMaster(newJobToCreate);
this.SubmitChanges();

当我运行this.SubmitChanges;

I will catch some very odd exceptions when I run this.SubmitChanges;

Index was outside the bounds of the array.

堆栈跟踪到不能进入的位置:

The stack trace goes places I cannot step into:

at System.Data.Linq.IdentityManager.StandardIdentityManager.MultiKeyManager`3.TryCreateKeyFromValues(Object[] values, MultiKey`2& k)
   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 JobTrakDataContext.CreateNewJob(NewJob job, String userName) in D:\JobTrakDataContext.cs:line 1119

有没有人有任何工具或技术他们使用?我有一些简单的东西吗?

Does anyone have any tools or techniques they use? Am I missing something simple?

编辑
我已经设置了.net调试使用Slace的建议,但是.net 3.5代码尚不可用: http://referencesource.microsoft.com/netframework.aspx

EDIT2
根据sirrocco的建议,我已经更改为InsertOnSubmit,仍然有相同的错误。

EDIT2: I've changed to InsertOnSubmit as per sirrocco's suggestion, still getting the same error.

EDIT3:
我实现了Sam的建议,试图记录生成的SQL并捕获ChangeExceptoinException。这些建议并没有变得更清楚,我从来没有在我的异常被抛出时实际上生成SQL。

I've implemented Sam's suggestions trying to log the SQL generated and to catch the ChangeExceptoinException. These suggestions do not shed any more light, I'm never actually getting to generate SQL when my exception is being thrown.

EDIT4:
我找到一个适用于我的答案。它只是一个理论,但它已经修复了我目前的问题。

I found an answer that works for me below. Its just a theory but it has fixed my current issue.

推荐答案

首先,感谢大家的帮助,我终于找到了。

First, thanks everyone for the help, I finally found it.

解决方案是从项目中删除.dbml文件,添加一个空白的.dbml文件,并使用我的项目所需的表从服务器资源管理器

The solution was to drop the .dbml file from the project, add a blank .dbml file and repopulate it with the tables needed for my project from the 'Server Explorer'.

我在这样做时注意到了几件事:

I noticed a couple of things while I was doing this:


  • 系统中有几个表用两个单词命名,并在单词之间有一个空格,即Job Master。当我将该表拉回到.dbml文件中时,它将创建一个名为Job_Master的表,它将用下划线替换空格。

  • 在原始的.dbml文件中,我的开发人员经历了.dbml文件并删除了所有下划线,因此Job_Master将成为.dbml文件中的JobMaster。在代码中,我们可以更多地参考表格,对于我们来说,标准命名约定。

  • 我的理论是,在某处,从JobMaster到Job Master的翻译是在做投影时失去了,我不断提出阵列的界限错误。

这只是一个理论。如果有人可以更好地解释,我希望在这里有一个具体的答案。

It is only a theory. If someone can better explain it I would love to have a concrete answer here.

这篇关于调试LINQ to SQL SubmitChanges()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆