如何调试的LINQ to SQL InsertOnSubmit声明?声明、to、LINQ、InsertOnSubmit

由网友(守不住的情)分享简介:下面code seased工作。The following code seased to work.db.DBUsers.InsertOnSubmit(new DBUser{AllTheStuff = valuesBeyondYourWildestDreams});db.SubmitChanges();我的猜测...

下面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.

阅读全文

相关推荐

最新文章