Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27350

Issues with Entity Framework

$
0
0
Hello all,

I am trying to get familiar with the Entity Framework to evaluate if it will be the way to go for my next project, a small POS software. To do so I found a tutorial for vb.net and EF dating back to 2008: http://www.vbforums.com/showthread.p...tity-Framework. However, for some reason I can't get past the first few simple lines of code.

To describe my own environment and code, similar to the one given in the above example:

I have created two entities through the entity framework designer. They are "User" and "Car", with a one to many relationship between them (however, at this stage I don't think that is relevant). I have pushed the model I have created to an SQL database, so that I can see the tables in that database, and I have added some records for "User" and "Car" in the database.

Next step is to show some data in a form. Following the example above, I have created a windows form with a single combo box (cmbFirstName) in it, and I have added the following code to form_load:

Code:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim userContext As New testdbEntities

        cmbFirstName.DataSource = userContext.User
        cmbFirstName.DisplayMember = "FirstName"

    End Sub

(Where FirstName is the name of the first name column).

At this stage, according to the howto, I should be able to run the application and see that some names are being fetched from the database and made visible in the combobox. But, the combobox remains blank.

Since this is about the simplest experiment I can think of, I am having a hard time seeing why it doesn't work. I figured it might be something with the SQL connection. But, the connection string was created for me automatically and it should be correct, since the database tables were - in fact - created.

This is a fairly old tutorial. Could it be that the syntax is different with VS2012 and EF 5.0?

Input appreciated!

Viewing all articles
Browse latest Browse all 27350

Trending Articles