开发者

How to debug a linq to sql InsertOnSubmit statement?

The following code sease开发者_如何转开发d 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.


For starters I would do:

db.Log = Console.Out;


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.


This works quite well at debugging linq to sql for us.

Its sends the log information to the output window.

http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11


You could also use LINQPad - copy your LINQ code into there, reference the database, and put dumps in to effectively debug the LINQ.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜