Click here to Skip to main content
12,450,581 members (48,230 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

20.3K views
10 bookmarked
Posted

LINQ to SQL – Execute SQL Queries

, 16 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
LINQ to SQL – Execute SQL Queries
In “LINQ to SQL”, we can use ExecuteQuery method of DataContext object to Execute SQL queries as follows:

Reference: LINQ to SQL – Execute SQL Queries.

class Program  
    {  
        static void Main(string[] args)  
        {  
            // create the context  
            NorthWindDataContext context = new NorthWindDataContext();  
      
            IEnumerable<Category> catList = context.ExecuteQuery<Category>(  
                "Select c1.CategoryId, c1.CategoryName from Categories as c1");  
      
            foreach (var item in catList)  
            {  
            Console.WriteLine(item.CategoryName);  
            }  
        }  
    }  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

A Mahesh
Web Developer
India India
Symphony Services, Banglore, 560 087, India

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Generalthanks, for the hard work. I was looking for this solution. Pin
digish77717-Oct-11 19:20
memberdigish77717-Oct-11 19:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160826.1 | Last Updated 16 Oct 2011
Article Copyright 2011 by A Mahesh
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid