Problem creating a simple Entity Framework sample project - combobox in a form not getting populated RRS feed

  • Question

  • I am trying to create a simple Entity Framework sample (winform) project which is based on another simple (winform) Entity Sample project that works. The original sample was created in VS2008, but I upgraded that sample to VS2012, and it still works.  In my new sample project I am trying to populate a combobox on a form with data from a Sql server database (sql server 2008 R2), but the combobox does not populate in my new sample EF project.  I noticed that the code generation strategy in the (original) working sample is set to "Default" and in my new sample it is set to "None".  I'm not so interested in "best practice" at this time (I think code generation strategy is best at "none" from my readings).  I am mainly interested in being able to populate this combobox using Entity Framework.   Below is a picture of the .edmx from my new sample project side by side with the .edmx from the original sample project which shows the differences between the two .edmx files.  I also put together a little desktop video which is only a few minutes long and shows exactly what I am doing (incase someone needs a little more detail).  If someone could be so kind as to take a look and advise me how I could populate this troublesome combobox using Entity Framework, I would be very grateful.

    -----      my EF sample video

    --picture of the two .edmx files side by side

    Rich P

    Wednesday, November 12, 2014 6:25 PM


  • OK, I figured it out.  I used some linq.  I recreated my sample project and when I added the ADO.Net Entity Model, I did not uncheck any of the options and left the Code Generation Strategy = None.  Then I only added code to the Load event of Form1.   I also added a BindingSource control to Form1.  Here is the code I added to the Load event of Form1

    private void Form1_Load(object sender, EventArgs e)
                var context = new PublishingCompanyEntities();
                var result = from a in context.Authors
                             select a;
                IList<Author> authList = result.ToList<Author>();
                bindingSource1.DataSource = authList;
                authorList.DataSource = bindingSource1.DataSource;
                authorList.DisplayMember = "FirstName";
    Now I can see the data in the combobox. 

    --this was actually a two part exercise -- part 1 was the coding, part 2 was creating a desktop video of part 1 :).

    Rich P

    • Edited by Rich P123 Thursday, November 13, 2014 8:14 AM .....
    • Marked as answer by Fred BaoModerator Friday, November 21, 2014 8:19 AM
    Thursday, November 13, 2014 1:10 AM