If you find this article useful, consider making a small donation to show your support for this web site and its content.
DiscountASP
AboutMe
About me:
Hi. My name is Farooq Kaiser and I'm a software developer from Toronto, Canada.

Querying with Entity SQL

by Farooq Kaiser 9. June 2009 13:59
CreateQuery(T) Method creates an ObjectQuery(T) in the current object context by using the specified T-SQL-like query language. I will replace ADO.NET Entity Framework example with Entity SQL Query.
 
private void button1_Click(object sender, EventArgs e)
        {
              
            using (var context = new AdventureWorksEntities1())
            {

                var q = "SELECT VALUE c " +
                 "FROM Contact AS c " +
                 "WHERE c.LastName='Clark'";
                var contacts = context.CreateQuery<Contact>(q);
                dataGridView1.DataSource = contacts.ToList(); 
            }
           
 }
 
The above query will return all the contacts that have lastname equal to Clark.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET | C#

Comments

Jobs Autos Real estate Videos Power by Google