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.