如何调试linq到sql的InsertOnSubmit语句? [英] How to debug a linq to sql InsertOnSubmit statement?

查看:151
本文介绍了如何调试linq到sql的InsertOnSubmit语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  db.DBUsers.InsertOnSubmit(new DBUser 
{
AllTheStuff = valuesBeyondYourWildestDreams
}
);
db.SubmitChanges();

我的猜测是在数据库中发生了变化,因为映射关闭,提交失败。 >
由于linq的视觉效果器对我来说并不奏效(用于修复的积分),我想找到另一种方式来知道到底出了什么问题,以及为什么默认的提交失败。



更新

我尝试使用

  db.SubmitChanges(ConflictMode.FailOnFirstConflict); 

得到一个例外,但似乎提交工作。除非数据库中没有实际的新实体。

解决方案

如果可以尝试使用SQL Server Profiler一个新的跟踪,连接到相关的数据库,然后选择要捕获的事件。



对于基本的LINQ调试,我发现SP:StmtCompleted (在Stored Procedures下)和 SQL:StmtCompleted (在TSQL下)足以显示什么SQL LINQ正在尝试运行。



如果你发现你正在拾取很多不需要的命令,你可以过滤出来。例如,我过滤掉从 msdb 主数据库数据库中的所有内容。


The following code seased to work.

db.DBUsers.InsertOnSubmit(new DBUser
    {
        AllTheStuff = valuesBeyondYourWildestDreams
    }
);
db.SubmitChanges();

My guess is something changed at the database and the submit is failing because the mapping is off.
As the linq visualiser isn't working for me (bonus points for fixing that) I want to find another way to know what exactly is going wrong and why the submit is failing silently.

Update
I tried using

db.SubmitChanges(ConflictMode.FailOnFirstConflict);

to get an exception, but it seems the submit works. Except that there is no actual new entity in the database.

解决方案

You could try using SQL Server Profiler if it's an option - start a new trace, connect to the relevant database, then select which events you want to capture.

For basic LINQ debugging, I've found that SP:StmtCompleted (under Stored Procedures) and SQL:StmtCompleted (under TSQL) are enough to show you what SQL LINQ is trying to run.

If you find you're picking up lots of unwanted commands, you can filter these out. For example, I filter out everything coming from the msdb and master databases.

这篇关于如何调试linq到sql的InsertOnSubmit语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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