The entity Framework enables us to bind Windows form controls, ASP.Net controls, WPF controls and Silverlight controls to an ObjectResult. An ObjectResult is returned when ObjectQuery is executed.
In the below code, to retrieve customer entities, we execute the statement - context.Customer without building a query. The context will construct and execute a query to return the Customer entities. We will bind this results to the Listbox using DataSource property.
The statement context.Customer;
returns the type of ObjectQuery in EF3.5. In EF 4.0, the type of Objectset is returned. Objectset is inherited form Objectquery and IobjectSet<T>.
private void Form1_Load(object sender, EventArgs e)
var context = new SalesOrderManagementEntities();
listBox1.DataSource = context.Customer;
listBox1.DisplayMember = "Name";