none
What Kind Of Linq Are You?

    Question

  • (My post title reminds me of the old Frank Zappa song "What kind of girl do you think we are?"  Love that song.)

    I have added an ADO.NET Entity Data Model to my project and I am able to query data from the database.  But I am confused about where to find more information about writing queries in Linq.  I see Linq to SQL, Linq to XML, Linq to Entities, and others.  Frankly my favorite was always Linq to the Past.  Sorry, that's a Nintendo joke.

    So I created this test loop in my project and it works.  It has two different style queries and they both work.  The first has an object style with operators like .Where.  The second has a more SQL style with operators like where.  Am I already bilingual in Linq?  What are these two types of Linq syntax called?  Can Microsoft please hurry up and make a dozen more Linq styles so that this will be more confusing?

            private void TestLoop()
            {
                using (var oContext = new PollingEntities())
                {
                    DateTime dTestDate = new DateTime(2015, 3, 12);
                    var oTerminalStats = oContext.term_stats_daily
                                        .Where(b => b.storeno == 65003 && b.ping_datetime >= dTestDate);
    
                    foreach (var oTerminalStat in oTerminalStats)
                    {
                        string sMessage = "ping at " + oTerminalStat.ping_datetime.ToString("HH:mm:ss");
                        Debug.Print(sMessage);
                    }
                    int iCount = oTerminalStats.Count();
                    Debug.Print("iCount = " + iCount.ToString("0"));
    
                    var oTerminalStats2 = from n in oContext.term_stats_daily
                        where n.storeno == 65003 && n.ping_datetime >= dTestDate
                        select n;
    
                    foreach (var oTerminalStat in oTerminalStats2)
                    {
                        string sMessage = "ping 2 at " + oTerminalStat.ping_datetime.ToString("HH:mm:ss");
                        Debug.Print(sMessage);
                    }
                    int iCount2 = oTerminalStats.Count();
                    Debug.Print("iCount2 = " + iCount2.ToString("0"));
                }
            }


    MCSD .NET developer in Dallas, Texas




    • Edited by DallasSteve Thursday, March 12, 2015 1:20 PM
    Thursday, March 12, 2015 12:54 PM

Answers