如何调试的LINQ to SQL InsertOnSubmit声明? [英] How to debug a linq to sql InsertOnSubmit statement?

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

问题描述

下面code seased工作。

The following code seased to work.

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

我的猜测是什么改变了在数据库和提交失败,因为映射是关闭的。
由于LINQ Visualiser的工作不适合我(奖励积分用于固定的)我想找到另一种方式来知道究竟是怎么了,为什么提交失败默默地。

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.

推荐答案

您可以尝试使用SQL Server Profiler,如果它是一个选项 - 开始一个新的跟踪,连接到相关的数据库,然后选择你想要捕捉的事件。

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.

有关基本LINQ的调试,我发现的 SP:StmtCompleted事件的(在存储过程)和 SQL:StmtCompleted事件的(在TSQL)都足以告诉你什么SQL LINQ正试图运行。

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.

如果你发现你挑选了很多不必要的命令,就可以过滤这些出。例如,我过滤掉一切从的 MSDB 的未来和的数据库。

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 to SQL InsertOnSubmit声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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