Bee Eee Blog

c# logging linq to sql

by brian on Jan.01, 2009, under .NET, c#, linq, mmsql, sql

I’ve often been frustrated by the sql that linq produces.  Usually it’s really good, but occasionally it produced monstrosities.   The hard part is getting at the sql that’s produced by a function.  Hovering over the statement in the idea is a real pain so instead I created the following class that dumps the sql to a file

public class DCLogger : IDisposable
    {
        private StringWriter writer;

        public DCLogger(System.Data.Linq.DataContext dc)
        {
            writer = new StringWriter();
            dc.Log = writer;
        }

        #region IDisposable Members

        public void Dispose()
        {
            writer.Flush();
            System.IO.File.WriteAllText( "c:\\temp\\sql.log", writer.ToString() );
        }

        #endregion
    }

To use it just create it passing it you data context. The results are written to the file when it’s disposed.

  using( DCLogger( dc ) )
  {
    // ... some linq statement that executes
  }
:, , ,
155 comments for this entry:
  1. EVAN

    ████████►BUY VIAGRA◀███████…

    ████████▲▲▲▲▲▲▲▲▲████████…

  2. Alexander

    buy@viagra.online” rel=”nofollow”>…

    Need cheap generic VIAGRA?…

  3. Alexander4

    buy@generic.abana” rel=”nofollow”>…

    Need cheap generic ABANA?…

  4. Alexander7

    buy@generic.LEVITRA” rel=”nofollow”>…

    Need cheap generic LEVITRA?…

  5. FREDDIE

    Buy@Cheap.Coral.Calcium” rel=”nofollow”>…

    Buywithout prescription…

  6. PERRY

    Purchase@Coral.Calcium.Online” rel=”nofollow”>…

    Buywithout prescription…

  7. TERRENCE

    Purchase@Discount.Coral.Calcium” rel=”nofollow”>..

    Buyit now…

  8. SALVADOR

    Cheap@Coral.Calcium.Online” rel=”nofollow”>..

    Buygeneric meds…

  9. BRANDON

    Buy@Discount.Abana” rel=”nofollow”>..

    Buyno prescription…

  10. OTIS

    Purchase@Abana.Online” rel=”nofollow”>..

    Buydrugs without prescription…

  11. LEO

    Purchase@Cheap.Abana” rel=”nofollow”>…

    Buygeneric pills…

  12. LEWIS

    Order@Abilify.Without.Prescription” rel=”nofollow”>..

    Buynow it…

  13. EDUARDO

    Cheap@Generic.Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>..

    Buygeneric pills…

  14. RICARDO

    Buy@Cheap.Acai” rel=”nofollow”>..

    Buydrugs without prescription…

  15. WALLACE

    Get@Acai.Online” rel=”nofollow”>…

    Buygeneric drugs…

  16. DUSTIN

    Purchase@Coral.Calcium.Online” rel=”nofollow”>..

    Buygeneric drugs…

  17. ENRIQUE

    Order@Cheap.Abana” rel=”nofollow”>.

    Buynow it…

  18. MIKE

    Buy@Cheap.Coral.Calcium” rel=”nofollow”>.

    Buydrugs without prescription…

  19. ROY

    Buy@Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>…

    Buywithout prescription…

  20. EDGAR

    Buy@Acai.Online” rel=”nofollow”>.

    Buynow it…

  21. LANCE

    Buy@Acai.Online” rel=”nofollow”>…

    Buyno prescription…

  22. DENNIS

    Buy@Acai.Online” rel=”nofollow”>.

    Buyit now…

  23. FELIX

    Buy@Discount.Acai” rel=”nofollow”>…

    Buyit now…

  24. TRACY

    Order@Cheap.Acai” rel=”nofollow”>…

    Buywithout prescription…

  25. WILLIE

    Order@Cheap.Acai” rel=”nofollow”>…

    Buygeneric drugs…

  26. ALFRED

    Order@Discount.Acai” rel=”nofollow”>…

    Buynow…

  27. JEFFREY

    Purchase@Acai.Online” rel=”nofollow”>…

    Buynow it…

  28. DONALD

    Purchase@Cheap.Acai” rel=”nofollow”>…

    Buyit now…

  29. RUSSELL

    Purchase@Cheap.Acai” rel=”nofollow”>..

    Buywithout prescription…

  30. ALVIN

    Cheap@Acai.Online” rel=”nofollow”>..

    Buynow it…

  31. JUAN

    Buy@Generic.Acai” rel=”nofollow”>..

    Buydrugs without prescription…

  32. VICTOR

    Order@Acai.Without.Prescription” rel=”nofollow”>.

    Buygeneric drugs…

  33. TERRENCE

    Buy@Cheap.Energy.Boost” rel=”nofollow”>.…

    Buygeneric drugs…

  34. RICK

    Order@Energy.Boost.Online” rel=”nofollow”>.…

    Buygeneric drugs…

  35. MATHEW

    Purchase@Cheap.Energy.Boost” rel=”nofollow”>.…

    Buyno prescription…

  36. BILLY

    Get@Accupril.Online” rel=”nofollow”>.…

    Buygeneric drugs…

  37. SAM

    Purchase@Accutane.Online” rel=”nofollow”>.…

    Buynow it…

  38. WILLIAM

    Buy@Aciphex.Online” rel=”nofollow”>.…

    Buygeneric pills…

  39. ANGELO

    Cheap@Aciphex.Online” rel=”nofollow”>.…

    Buynow it…

  40. ADAM

    Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>.…

    Buyno prescription…

  41. RUBEN

    Order@Acomplia.Online” rel=”nofollow”>.…

    Buygeneric meds…

  42. BOB

    Order@Discount.Acomplia” rel=”nofollow”>.…

    Buygeneric drugs…

  43. ARTHUR

    Buy@Actonel.Without.Prescription” rel=”nofollow”>.…

    Buygeneric meds…

  44. TONY

    Cheap@Actonel.Without.Prescription” rel=”nofollow”>.

    Buyno prescription apx…

  45. DARYL

    Purchase@Generic.Actonel.35mg” rel=”nofollow”>..

    Buygeneric drugs krg…

  46. RAY

    Purchase@Cheap.Actoplus.Met” rel=”nofollow”>.

    Buygeneric drugs zfk…

  47. BERNARD

    Purchase@Cheap.Actos” rel=”nofollow”>..

    Buynow it vhx…

  48. LLOYD

    Purchase@Discount.Actos” rel=”nofollow”>…

    Buywithout prescription xiu…

  49. JEREMIAH

    Cheap@Actos.Online” rel=”nofollow”>..

    Buynow it tly…

  50. CLIFTON

    Cheap@Generic.Actos” rel=”nofollow”>..

    Buygeneric meds qmo…

  51. VICTOR

    Purchase@Generic.Actos.15mg.30mg” rel=”nofollow”>..

    Buygeneric pills zdg…

  52. EVERETT

    Purchase@Cheap.Adalat” rel=”nofollow”>..

    Buygeneric meds abx…

  53. LUIS

    Buy@Coral.Calcium.Online” rel=”nofollow”>…

    Buyit now oil…

  54. BRUCE

    Get@Acai.Online” rel=”nofollow”>…

    Buynow it zdg…

  55. RONALD

    Buy@Acai.Without.Prescription” rel=”nofollow”>.

    Buygeneric drugs itj…

  56. MARVIN

    Order@Acai.Without.Prescription” rel=”nofollow”>.

    Buynow it lmg…

  57. CHRISTOPHER

    Buy@Energy.Boost.Online” rel=”nofollow”>..

    Buynow it cey…

  58. MITCHELL

    Purchase@Energy.Boost.Online” rel=”nofollow”>..

    Buydrugs without prescription faj…

  59. GERARD

    Get@Accupril.Online” rel=”nofollow”>..

    Buyit now irl…

  60. JOHNNY

    Order@Generic.Accutane” rel=”nofollow”>…

    Buygeneric meds svb…

  61. JASON

    Buy@Cheap.Aciphex” rel=”nofollow”>…

    Buywithout prescription ccw…

  62. JOEL

    Buy@Discount.Aciphex” rel=”nofollow”>..

    Buyno prescription wkp…

  63. JERRY

    Purchase@Aciphex.Online” rel=”nofollow”>…

    Buydrugs without prescription vrg…

  64. LEWIS

    Purchase@Cheap.Aciphex” rel=”nofollow”>.

    Buygeneric drugs axm…

  65. MARION

    Cheap@Aciphex.Online” rel=”nofollow”>..

    Buyno prescription gdt…

  66. GLENN

    Buy@Aciphex.Without.Prescription” rel=”nofollow”>..

    Buyno prescription tao…

  67. DALE

    Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>…

    Buyit now knc…

  68. VINCENT

    Purchase@Aciphex.Without.Prescription” rel=”nofollow”>.

    Buydrugs without prescription xab…

  69. NORMAN

    Cheap@Aciphex.20mg” rel=”nofollow”>.

    Buyit now ojb…

  70. BRETT

    Buy@Generic.Aciphex.20mg” rel=”nofollow”>…

    Buydrugs without prescription jlg…

  71. RANDY

    Purchase@Discount.Acomplia” rel=”nofollow”>…

    Buydrugs without prescription ttp…

  72. NEIL

    Purchase@Discount.Acomplia” rel=”nofollow”>.

    Buydrugs without prescription tdg…

  73. VERNON

    Purchase@Discount.Acomplia” rel=”nofollow”>…

    Buynow ela…

  74. NICHOLAS

    Buy@Actonel.Online” rel=”nofollow”>.

    Buygeneric pills oir…

  75. NICK

    Buy@Discount.Actonel” rel=”nofollow”>..

    Buyno prescription lka…

  76. DWIGHT

    Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.

    Buygeneric drugs ouw…

  77. RICARDO

    Buy@Cheap.Advair” rel=”nofollow”>.

    Buygeneric drugs hwi…

  78. FRED

    Purchase@Advair.Online” rel=”nofollow”>..

    Buyno prescription jui…

  79. AARON

    Buy@Generic.Advair.Without.Prescription” rel=”nofollow”>..

    Buyno prescription jwi…

  80. ALEXANDER

    Order@Aggrenox.Online” rel=”nofollow”>…

    Buyit now sge…

  81. FREDRICK

    abilify@and.gemfibrozil” rel=”nofollow”>.

    Buyno prescription…

  82. ANGELO

    aciphex@cancer.buy” rel=”nofollow”>..

    Buygeneric drugs…

  83. HUBERT

    alphagan@refrigerated.buy” rel=”nofollow”>…

    Buygeneric drugs…

  84. MAX

    amantadine@hydrochloride.tablets” rel=”nofollow”>..

    Buygeneric drugs…

  85. KEN

    arava@adverse.events” rel=”nofollow”>…

    Buygeneric meds…

  86. BRYAN

    can@you.get.acai.berries.in.the.grocery.store” rel=”nofollow”>.

    Buydrugs without prescription…

  87. GENE

    aciphex@muscle.pain” rel=”nofollow”>..

    Buygeneric pills…

  88. AUSTIN

    actos@side.effects.edema” rel=”nofollow”>..

    Buygeneric drugs…

  89. RAFAEL

    arjuna@pills.buy” rel=”nofollow”>..

    Buygeneric meds…

  90. TYLER

    buy@real.strong.armour” rel=”nofollow”>.

    Buydrugs without prescription…

  91. DUSTIN

    weight loss disclaimer law

    Buy_drugs without prescription…

  92. CHRIS

    cancer of spine

    Buy_without prescription…

  93. DENNIS

    low fat diets history

    Buy_drugs without prescription…

  94. JOEL

    how to get teens off drugs

    Buy_drugs without prescription…

  95. DALE

    hot spots or cancer

    Buy_without prescription…

  96. RAMON

    children@prozac.buy” rel=”nofollow”>…

    Buywithout prescription…

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...