Tuesday, August 4, 2015

Select specific columns from Entity Framework

This helped:
http://stackoverflow.com/questions/19536064/entity-framework-select-multiple-columns


My code:
     private void buttonRefresh_Click(object sender, EventArgs e)
        {

            try
            {
                EnterpriseConfigurationRegistryEntities model = new EnterpriseConfigurationRegistryEntities();

                var p = model.ProductLists
                    .Include("Name")
                    .Select(x => new { x.Name }).ToList();


                BindingSource bi = new BindingSource();
                bi.DataSource = p;
                dataGridView1.DataSource = bi;
                dataGridView1.Columns[0].HeaderText = "Products";

            }
            catch (Exception ex)
            {
               
                throw;

            }