none
C# debug linq statements RRS feed

  • Question

  • When using the visual studio.net 2010 ide, I have not found a way to debug linq statements. This would also include linq to sql statements. Can you tell me how to debug linq statements?What window(s) should I use to see all the values? are there special editors like 'xml editors', 'notepad' and/or other tools I can use to see the values in fields that the linq query is being executed at?

    For exmple if i get an error that says 'invalid cast' operation. How can I tell what column(field) is being referred to?

    • Moved by Bob Shen Wednesday, February 6, 2013 6:42 AM
    Wednesday, February 6, 2013 2:09 AM

Answers

  • LINQ to SQL has debugging support, including the ability to see the generated SQL.

    For details, see: http://msdn.microsoft.com/en-us/library/bb386930.aspx

    For LINQ to Objects, the exception details will be pretty explicit.  Breaking your query up into multiple lines and multiple methods can help debugging if you can't figure out where it's causing issues.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, February 6, 2013 2:12 AM
  • Hi Wendy;

    LinqPad is a good and it's free tool to use to create and troubleshoot Linq query problems. You can download from this web site.

    LinqPad Website

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, February 7, 2013 3:58 AM

All replies

  • LINQ to SQL has debugging support, including the ability to see the generated SQL.

    For details, see: http://msdn.microsoft.com/en-us/library/bb386930.aspx

    For LINQ to Objects, the exception details will be pretty explicit.  Breaking your query up into multiple lines and multiple methods can help debugging if you can't figure out where it's causing issues.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, February 6, 2013 2:12 AM
  • The link you just provided is a good start for linq to sql errors. However, on one linq statement, I

    had the var linqresult = 'linq query' where I got the linqresult failed due to an 'invalid vast'. Thus, how can I use the debugger to find out what was causing the 'invalid cast' operation?

    I found that one of the database columns had a 'bad' defintition for a data type.

    Wednesday, February 6, 2013 2:25 AM
  • The link you just provided is a good start for linq to sql errors. However, on one linq statement, I

    had the var linqresult = 'linq query' where I got the linqresult failed due to an 'invalid vast'. Thus, how can I use the debugger to find out what was causing the 'invalid cast' operation?

    I found that one of the database columns had a 'bad' defintition for a data type.

    Look at the details of the exception you receive.  It should provide you with a lot of this information. 

    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, February 6, 2013 5:10 PM
  • Hi Wendy;

    LinqPad is a good and it's free tool to use to create and troubleshoot Linq query problems. You can download from this web site.

    LinqPad Website

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, February 7, 2013 3:58 AM