LINQ to SQL syntax

Posted on 2011-10-25
Last Modified: 2012-05-12
Can someone show me the LINQ to SQL equivalent  of the following query?

select site, COUNT(site) as Site_count from V_Sites group by site order by Site_count desc

I would like the method that contains the LINQ query to return a value
Question by:wademi
    1 Comment
    LVL 4

    Accepted Solution

    Hi Wademi

    you can do what your asking by doing this:

    var siteCount = from s in sites 
    group s by s.Name into g
    select new { Site = g.Key, SiteCount = g.Count() };

    Open in new window

    This link contains many samples and is a good reference.

    MSDN 101 Linq Samples

    Thanks Gruff

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now