1

I'm using EF7 and SQLite in a Windows Form Project with VS2013. I created a Context Class that inheretes DbContext and create a DbSet for each of these 3 classes that represent my tables.

public DbSet<Server> Servers { get; set; }

I inserted data and I'm able to show it in a DataGridview Using this code:

myContext context = new myContext();
gridServer.DataSource=context.Servers.ToList();

The data shows in the grid but this approach dont let me sort, delete or add things. So I research and find out that I need to use a DataSource Object:

I added the Object but this is the part that confuses me.

  1. If I choose the Server Class the grid does not show anything except the name of the "fields" of that class. I'm guessing that is because the class has nothing to do with the database.

  2. So I chose myContext Class. This one has the SqliteConnection and also has the "Server" property that I used in the code to retrieve data so I guess this is the correct one. But when I picked this one I dont get the "fields" of the store class. All I got is a server column that is also empty and other columns that I have no idea were they came from.

This screen shows the grid that I fill with the code above in the right and my failed attempt with the SourceData Object in the left.

enter image description here

So I wonder if you could guide me. Since It looks like I'm missing some steps/configuration or something.

Thanks in advice.

Daniel Dudas
  • 2,972
  • 3
  • 27
  • 39

0 Answers0