none
I can't extract sql from linq query -- using EF6 DBcontext (VS2015) -- tables in the entity and linq query have relationships RRS feed

  • Question

  • myLinqQuery.ToString() only displays --  System.Collections.Generic.List`1[System.String]  in the text visualizer (VS2015) . 

    I have been able to get the sql when a linq query is an IQueryable, but ... in this case -- here is the setup

    AppInventoryEntities db = new AppInventoryEntities();  //--AppInventoryEntities is the context

    //--DeploymentBatch is a table in the entity -- EF6
    DeploymentBatch deploymentbatch = db.DeploymentBatches.Find(id);

    //--this is the actual query -- DeploymentBatchUsers is another table in the entity related/constrained to DeploymentBatch 
    var deptUsers = deploymentbatch.DeploymentBatchUsers.Select(b => b.UserID).ToList();  

    and here is what I tried for retrieving the sql from the query
    string sabc = deptUsers.ToString();  //--this only displays System.Collections.Generic.List`1[System.String]

    I also tried
    IQueryable<string> deptUsers2 = deploymentbatch.DeploymentBatchUsers.Select(b => b.UserID).ToList().AsQueryable();
    which also displayed the same thing -- System.Collections.Generic.List`1[System.String]. 

    I tried replacing <string> with <object> but compiler complained, I tried <DeploymentBatch> but got more casting errors.

    If the original query was IQueryable, then yes I have been able to use query.ToString() to get the sql.  But that not the case here.  How can I get the sql from the original query?


    Rich P

    Thursday, November 16, 2017 12:04 AM

All replies

  • well,  this wasn't very fun, but I finally got the stupid sql from my query.  For posterity, I share the following:

    I ended up using System.Data.Entity.Infrastructure.DbQuery and Reflection so that I could get/use ToTraceString()

    and in order to be able to apply System.Data.Entity.Infrastructure.DbQuery   I needed to take note that

      DeploymentBatch deploymentbatch = db.DeploymentBatches.Find(id);

    was returning something that was inconsistent with System.Data.Entity.Infrastructure.DbQuery.   So, I changed the query a tad and came up with the following which I can now retrieve the sql from .ToTraceString which it turns out that the sql reveals subqueries in the sql  (note:  I did this the not fun way as in "hit and miss" try this try that, don't really know what I'm doing -- just trying to make it work in the blind.  If someone can explain why this refactored query works instead of the original db....Find(id) Please have at it)

    var deptUsers2 = (System.Data.Entity.Infrastructure.DbQuery<IEnumerable<string>>)db.DeploymentBatches.Select(a => a.DeploymentBatchUsers.Select(b => b.UserID)).AsQueryable();
    //--get the IInternalQuery internal variable from the DbQuery object
    var iqProp = deptUsers2.GetType().GetProperty("InternalQuery", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
    var iq = iqProp.GetValue(deptUsers2, null);
    //--get the ObjectQuery internal variable from the IInternalQuery object
    var oqProp = iq.GetType().GetProperty("ObjectQuery", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
    var objectQuery = (System.Data.Entity.Core.Objects.ObjectQuery<IEnumerable<string>>)oqProp.GetValue(iq, null);
    
    string sabc = objectQuery.ToTraceString();


    Rich P



    • Edited by Rich P123 Thursday, November 16, 2017 6:41 PM .......
    Thursday, November 16, 2017 6:39 PM
  • Hi Rich P123,

    >>If the original query was IQueryable, then yes I have been able to use query.ToString() to get the sql.  But that not the case here.  How can I get the sql from the original query?

    According to your description and related code, you use entity framework6 and you want to get the SQL statement from the original query. I would suggest that you could use database logging to trace related SQL.

    Starting with Entity Framework 6, anytime Entity Framework sends a command to the database this command can be intercepted by application code. This is most commonly used for logging SQL, but can also be used to modify or abort the command.

    Here is a simple console app for your reference.

     using (var db = new EFDemoEntities())
    {
        db.Database.Log = Console.Write;
    
        var blog = db.Blogs.Find(1);
    
        var postIds = blog.Posts.Select(t => t.PostId);
    
        Console.ReadKey();
    }

    For more information, please refer to:

    https://msdn.microsoft.com/en-us/library/dn469464(v=vs.113).aspx

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 17, 2017 5:59 AM
    Moderator
  • Hi Rich P123,

    Queryable uses a DbQueryProvider(IQueryProvider) to translate the expression (the chained extension methods) into a singledatabase query (in this case, it generates T-SQL to run against the database). Once the query is invoked (by say, enumerating it), the query is executed against the database and the results are returned back to be consumed.

    For more information, please refer to:

    https://www.developerhandbook.com/entity-framework/in-the-spotlight-demystifying-iqueryable-entity-framework-6/

    Note: This response contains a reference to a third party World Wide Web site.
    Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.  

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 17, 2017 6:13 AM
    Moderator

  •  using (var db = new EFDemoEntities())
    {
        db.Database.Log = Console.Write;
    
        var blog = db.Blogs.Find(1);
    
        var postIds = blog.Posts.Select(t => t.PostId);
    
        Console.ReadKey();
    }

    Thank you for your reply.  I just tried this -- I added db.Database.Log = Console.Write; (per your example and the article which you gave the link to).  If I add Console.ReadKey();  after my linq Query -- my application just hangs.  I looked in the VS2015 console and tried pressing (any) key on the keyboard, but nothing showed up.  I also opened up the VS command prompt to see if anything showed up there, but I did not see anything.

    I commented out the Console.ReadKey();  line and I assume db.Database.Log wrote to somewhere.  My question is now this -- where do I go to see the output of db.Database.Log?


    Rich P


    • Edited by Rich P123 Friday, November 17, 2017 5:35 PM ......
    Friday, November 17, 2017 5:35 PM
  • Hi Rich,

    >>commented out the Console.ReadKey();  line and I assume db.Database.Log wrote to somewhere.  My question is now this -- where do I go to see the output of db.Database.Log?

    My sample is a console App, what kind of project template you are using?

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 21, 2017 1:29 AM
    Moderator
  • My sample is a console App, what kind of project template you are using?

    This is an MVC5 app. Normally I just set a string var to the Linq based list and get the sql from that

    var qry = db.myEntity.Select(a => a.fld1).ToList();
    string s = qry.ToString();
    System.Diagnostics.Debug.Print(s);

    but for the linq query in question here -- this technique just gives me

    System.Collections.Generic.List`1[System.String]

    even though the query itself does return a list.  I want to see the sql that generates that list.  The db.Database.Log method seems like a possible solution, but how to I retrieve the content from this?


    Rich P


    • Edited by Rich P123 Tuesday, November 21, 2017 5:04 PM .......
    Tuesday, November 21, 2017 4:52 PM
  • Hi Rich P123,

    >>db.Database.Log method seems like a possible solution, but how to I retrieve the content from this?

    You could use the following code, which show related SQL statement in Output Window.

    using (var db = new EFDemoContext())
                {
                    db.Database.Log = message => Trace.WriteLine(message);
                                   db.Database.Log = logFile.Write;
                    var blog = db.Blogs.Find(1);
                    var postIds = blog.Posts.Select(t => t.PostId);
                }

     

    Or use the following code, which save the SQL statement into txt file.

    using (var db = new EFDemoContext())
                {
                  var logFile = new StreamWriter("C:\\log.txt");
                    db.Database.Log = logFile.Write;
                    var blog = db.Blogs.Find(1);
                    var postIds = blog.Posts.Select(t => t.PostId);
    
                    logFile.Close();
                }

    Best regards,

    Zhanglong Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 22, 2017 3:13 AM
    Moderator

  • using (var db = new EFDemoContext())
    {
        db.Database.Log = message => Trace.WriteLine(message);
        db.Database.Log = logFile.Write;
        var blog = db.Blogs.Find(1);
        var postIds = blog.Posts.Select(t => t.PostId);
    }

    Thank you again for this suggestion.  I tried it -- but -- VS2015 complained that it did not recognize

    logFile

    so I commented out //db.Database.Log = logFile.Write;

    when I ran the app I got the following result in the output window -- it was a little more than what I was expecting, but it did return the sql (I think this is what I was looking for -- except included values, although it also returned the actual value in the main paramenter -- p__linq__0: '16' (Type = Int32)

    SELECT 
        [Extent1].[DeploymentStatusID] AS [DeploymentStatusID], 
        [Extent1].[Status] AS [Status], 
        [Extent1].[Description] AS [Description], 
        [Extent1].[ModDt] AS [ModDt], 
        [Extent1].[RowVersion] AS [RowVersion], 
        [Extent1].[ModUser] AS [ModUser]
        FROM [dbo].[DeploymentStatus] AS [Extent1]
        WHERE [Extent1].[DeploymentStatusID] = @EntityKeyValue1
    
    
    -- EntityKeyValue1: '1' (Type = Int32)
    
    -- Executing at 11/22/2017 12:08:50 PM -08:00
    
    -- Completed in 159 ms with result: SqlDataReader
    
    
    
    Closed connection at 11/22/2017 12:08:50 PM -08:00
    
    Opened connection at 11/22/2017 12:08:50 PM -08:00
    
    SELECT 
        [Project139].[DeploymentAppSnapshotID] AS [DeploymentAppSnapshotID], 
        [Project139].[SnapShotDt] AS [SnapShotDt], 
        [Project139].[C3] AS [C1], 
        [Project139].[C1] AS [C2], 
        [Project139].[C2] AS [C3]
        FROM ( SELECT 
            [Project138].[DeploymentAppSnapshotID] AS [DeploymentAppSnapshotID], 
            [Project138].[SnapShotDt] AS [SnapShotDt], 
            [Project138].[C1] - [Project138].[C3] AS [C1], 
            [Project138].[C4] - [Project138].[C5] AS [C2], 
            [Project138].[C2] AS [C3]
            FROM ( SELECT 
                [Project137].[C1] AS [C1], 
                [Project137].[DeploymentAppSnapshotID] AS [DeploymentAppSnapshotID], 
                [Project137].[SnapShotDt] AS [SnapShotDt], 
                [Project137].[C2] AS [C2], 
                [Project137].[C3] AS [C3], 
                [Project137].[C4] AS [C4], 
                (SELECT 
                    COUNT(1) AS [A1]
                    FROM [dbo].[DeploymentAppSnapshotDtl] AS [Extent5]
                    WHERE ([Project137].[DeploymentAppSnapshotID] = [Extent5].[DeploymentAppSnapshotID]) AND ([Extent5].[AppCIID] IN (604, 475, 626, 123, 81, 7, 853, 2, 3, 669, 224, 606, 931, 1114, 196, 1396, 193, 116, 1771, 1788, 347, 1049, 1751, 1321, 1496, 1986, 533, 1067, 1521, 1090, 1207, 98, 1112, 1148, 1239, 558, 1097, 1063, 1307, 1203, 1341, 2172, 2219, 886, 420, 1110, 870, 874, 464, 1240, 1755, 1128, 1209, 1405, 1347, 2223, 1233, 1267, 1354, 1597, 1697, 1769, 1199, 2203, 1750, 1108, 1342, 1988, 1505, 1740, 1506, 1531, 1749, 1206, 2174, 634, 2220, 668, 929, 2224, 1495, 1542, 2188, 1302, 1790, 1546, 2216, 2254, 1839, 2133, 1982, 2140, 2176, 1258, 1260, 1310, 1409, 1642, 1122, 1400, 2215, 1984, 2190, 2233, 1804, 2221, 1695, 1709, 1760, 1777, 2222, 1344, 2041, 2182, 2027, 2177, 1710, 1796, 1846, 1729, 2077, 2214, 1744, 1994, 2196, 2228, 2213, 2179, 2229, 2264, 2245, 825, 890, 1761))) AS [C5]
                FROM ( SELECT 
                    [Project136].[C1] AS [C1], 
                    [Project136].[DeploymentAppSnapshotID] AS [DeploymentAppSnapshotID], 
                    [Project136].[SnapShotDt] AS [SnapShotDt], 
                    [Project136].[C2] AS [C2], 
                    [Project136].[C3] AS [C3], 
                    (SELECT 
                        COUNT(1) AS [A1]
                        FROM [dbo].[DeploymentAppSnapshotDtl] AS [Extent4]
                        WHERE [Project136].[DeploymentAppSnapshotID] = [Extent4].[DeploymentAppSnapshotID]) AS [C4]
                    FROM ( SELECT 
                        [GroupBy2].[A1] AS [C1], 
                        [Project1].[DeploymentAppSnapshotID] AS [DeploymentAppSnapshotID], 
                        [Project1].[SnapShotDt] AS [SnapShotDt], 
                        [Project1].[C1] AS [C2], 
                        (SELECT 
                            COUNT(1) AS [A1]
                            FROM [dbo].[DeploymentAppSnapshotDtl] AS [Extent3]
                            WHERE ([Project1].[DeploymentAppSnapshotID] = [Extent3].[DeploymentAppSnapshotID]) AND ([Extent3].[AppCIID] IN (604, 475, 626, 123, 81, 7, 853, 2, 3, 669, 224, 606, 931, 1114, 196, 1396, 193, 116, 1771, 1788, 347, 1049, 1751, 1321, 1496, 1986, 533, 1067, 1521, 1090, 1207, 98, 1112, 1148, 1239, 558, 1097, 1063, 1307, 1203, 1341, 2172, 2219, 886, 420, 1110, 870, 874, 464, 1240, 1755, 1128, 1209, 1405, 1347, 2223, 1233, 1267, 1354, 1597, 1697, 1769, 1199, 2203, 1750, 1108, 1342, 1988, 1505, 1740, 1506, 1531, 1749, 1206, 2174, 634, 2220, 668, 929, 2224, 1495, 1542, 2188, 1302, 1790, 1546, 2216, 2254, 1839, 2133, 1982, 2140, 2176, 1258, 1260, 1310, 1409, 1642, 1122, 1400, 2215, 1984, 2190, 2233, 1804, 2221, 1695, 1709, 1760, 1777, 2222, 1344, 2041, 2182, 2027, 2177, 1710, 1796, 1846, 1729, 2077, 2214, 1744, 1994, 2196, 2228, 2213, 2179, 2229, 2264, 2245, 825, 890, 1761))) AS [C3]
                        FROM   (SELECT 
                            [Extent1].[DeploymentAppSnapshotID] AS [DeploymentAppSnapshotID], 
                            [Extent1].[SnapShotDt] AS [SnapShotDt], 
                            (SELECT 
                                COUNT(1) AS [A1]
                                FROM [dbo].[DeploymentAppSnapshotDtl] AS [Extent2]
                                WHERE [Extent1].[DeploymentAppSnapshotID] = [Extent2].[DeploymentAppSnapshotID]) AS [C1]
                            FROM [dbo].[DeploymentAppSnapshot] AS [Extent1]
                            WHERE [Extent1].[DeploymentBatchID] = @p__linq__0 ) AS [Project1]
                        CROSS JOIN  (SELECT 
                            COUNT(1) AS [A1]
                            FROM  (SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable2]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable3]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable4]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable5]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable6]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable7]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable8]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable9]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable10]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable11]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable12]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable13]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable14]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable15]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable16]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable17]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable18]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable19]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable20]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable21]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable22]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable23]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable24]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable25]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable26]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable27]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable28]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable29]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable30]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable31]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable32]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable33]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable34]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable35]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable36]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable37]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable38]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable39]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable40]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable41]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable42]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable43]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable44]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable45]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable46]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable47]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable48]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable49]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable50]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable51]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable52]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable53]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable54]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable55]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable56]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable57]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable58]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable59]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable60]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable61]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable62]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable63]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable64]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable65]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable66]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable67]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable68]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable69]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable70]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable71]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable72]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable73]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable74]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable75]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable76]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable77]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable78]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable79]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable80]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable81]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable82]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable83]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable84]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable85]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable86]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable87]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable88]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable89]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable90]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable91]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable92]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable93]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable94]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable95]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable96]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable97]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable98]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable99]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable100]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable101]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable102]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable103]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable104]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable105]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable106]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable107]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable108]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable109]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable110]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable111]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable112]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable113]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable114]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable115]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable116]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable117]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable118]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable119]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable120]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable121]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable122]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable123]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable124]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable125]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable126]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable127]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable128]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable129]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable130]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable131]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable132]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable133]
                            UNION ALL
                                SELECT 
                                1 AS [C0]
                                FROM  ( SELECT 1 AS X ) AS [SingleRowTable134]) AS [UnionAll133] ) AS [GroupBy2]
                    )  AS [Project136]
                )  AS [Project137]
            )  AS [Project138]
        )  AS [Project139]
        ORDER BY [Project139].[SnapShotDt] DESC
    
    
    -- p__linq__0: '16' (Type = Int32)
    
    -- Executing at 11/22/2017 12:08:50 PM -08:00
    
    -- Completed in 289 ms with result: SqlDataReader
    
    Closed connection at 11/22/2017 12:08:50 PM -08:00
    
    The thread 0x8a0c has exited with code 0 (0x0).


    Rich P

    Wednesday, November 22, 2017 8:14 PM