Dieter Depuydt
Dieter Depuydt

Reputation: 21

Strange LINQ to SQL behaviour (BUG?)

We have this very strange issue on LINQ to SQL Code.

Consider this code snippet :

var wissen = db.Table.Where(f => f.Name == somevalue);
db.Table.DeleteAllOnSubmit(wissen);
db.SubmitChanges();

This works as expected on our dev servers, but when we are deploying this to our production server it doesn't give any errors but it doesn't delete anything neither altough it should.

When we replace this code with this :

db.ExecuteCommand("DELETE FROM Table WHERE Name = {0}", somevalue);

thing work just fine.

The workaround works just fine, but we would be happy to know what exactly goes wrong.

Looking forward to your comments :)

Dieter

Upvotes: 1

Views: 159

Answers (2)

Dour High Arch
Dour High Arch

Reputation: 21722

Is db a System.Data.Linq.DataContext? If not, try using one. If it is, call db.Log = Console.Out after instantiating, and it will send all the generated SQL to the Visual Studio output console. This should show what is going wrong.

If you can't run VS on the server, log output to a text file:

StreamWriter sw = new StreamWriter(pathToLogFile);
db.Log = sw;
// do your queries here
sw.Flush();

Upvotes: 1

Mark Seemann
Mark Seemann

Reputation: 233417

Have you tried to do a SQL Profiler trace on the production machine to find out which SQL is being emitted?

This should help you troubleshoot the issue.

Upvotes: 2

Related Questions