Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
335
WinGrid databinding with Entity Framework
posted

Hello, I am trying to bind a WinGrid to my simple Entity Framework CodeFirst data. I created a few simple models, a DBContext, an implementation of a generic Repository Pattern and a UnitOfWork DataaccessLayer to access my database.

But I'm having problems binding the grid to it, as all the datasources somehow do not work and the EntityDataSource does not exist anymore in the latest EF/.NET version. The only way that seems to work, is to surpass the repository and access the DbSet directly:

grid.DataSource = dal.getContext().Students.Local.ToBindingList();

dal is an object of a class containing all the repositories, and getContext returns the DBContext containing all the DbSet's.

It works, but it feels rather....dirty. Usually, the Entity Framework offers such amazing and simple features, but binding to Controls (not only infragistics) seems to be a huge pain. Is there really no way to use visual binding and automatically generated Data/column schemes and all that stuff I had with old ado.net datasets?

Parents
  • 21795
    Offline posted

    Hello Kevin,

    When using Entity Framework Code First you can create visual binding by following next steps in Visual Studio 2013 (as you would do this for any other component):

    • On Main Menu select Project -> Add New Data Source.

    • Select Object and click ‘Next’.

    • In Select the Data Objects select the necessary objects from your Data First Model

    • Click Finish.

    • Show Data Sources (Main Menu -> View -> Other Windows -> Data Sources).

    • Select the necessary data source class and drag and drop it over the UltraGrid. This way UltraGrid is bound to the binding source.

    Please follow the next link for more information regarding Entity Framework Code First data biding http://blogs.msdn.com/b/adonet/archive/2011/02/16/ef-feature-ctp5-code-first-and-winforms-databinding.aspx

    Please note whenever way you bind the data all the changes need to be populate to database with DbContex.SaveChanges() method.

    Please let me know if this is what you are looking for or if I am missing something.

Reply Children