Click here to Skip to main content
Click here to Skip to main content

LINQ to SQL – Execute SQL Queries

By , 16 Oct 2011
 
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)

About the Author

A Mahesh
Web Developer
India India
Symphony Services, Banglore, 560 087, India
Follow on   Twitter

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalthanks, for the hard work. I was looking for this solution.memberdigish77717-Oct-11 19:20 

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

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