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

查看:19
本文介绍了调试 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?

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

EDIT: I've setup .net debugging using Slace's suggestion, however the .net 3.5 code is not yet available: 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.

我已经实施了 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.

我在下面找到了一个对我有用的答案.这只是一个理论,但它解决了我当前的问题.

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天全站免登陆