Sql Server Query Visualizer – Cannot see generated

2019-09-06 19:39发布

问题:

I have SqlServerQueryVisualizer. I can see the SQL when I hover on “accounts” variable. But when I hover on “results” variable, it is not showing the SQL query. How to see the SQL query for “results” variable in the following code?

    public IEnumerable<T> FindAll(Func<T, bool> predicate)
    {

        LibraryManagementClassesDataContext db = new LibraryManagementClassesDataContext("");
        var accounts = from p in db.Accounts
                       where p.AccountNumber == 1
                       select p;

        //Where
        var results = Context.GetTable<T>().Where(predicate);
        return results;
    }

Also, I have a insert function. How to see the generated query for this scenario?

    public virtual void InsertOnSubmit(T entity)
    {
        GetTable().InsertOnSubmit(entity);
    }

回答1:

Not 100% sure if this lack of the hover working is caused by the generics or what (it seems to have resolved the generic in the screenshot you gave), but you can always use the DataContext.Log property to capture the SQL to a reader. I know it's not as convenient, but it might be more readable than in the hover.



回答2:

The problem stated in the question still exists.

Currently I am using the following class for seeing the result in output window.

context.Log = new OutputWindowWriter();

class OutputWindowWriter : System.IO.TextWriter
{
    public override void Write(char[] buffer, int index, int count)
    {
        System.Diagnostics.Debug.Write(new String(buffer, index, count));
    }

    public override void Write(string value)
    {
        System.Diagnostics.Debug.Write(value);
    }

    public override System.Text.Encoding Encoding
    {
        get { return System.Text.Encoding.Default; }
    }
}