How to create trivial CRUD app using data binding and Entity Framework?

D

Dan Mayolo

I tried following the steps I describe below in VS 2010, but to no avail:

· Create new Windows Forms App. Project

· Add new empty ADO EDM to Project

· Add new entity Customer with scalar properties FirstName and
LastName

· Generate db script with EDM

· Execute db script to create tables in the db

· Add new Object Data Source based on EDM Model1

· Select object Customer in Data Sources window and drop it on form
in form of Details view.

· All typical binding controls are created, all I need to do is to
enable the Save button.





I run the app, form is displayed. I can add new records and navigate between
them. I press save, but when I reinitialize the app, all data is lost. I
guess code on the form should only reference BindingDataSource, not the
ObjectContext directly?

I tried setting the customerBindingSource.DataSource = ctx.Customers and
saving changes via ctx.SaveChanges(), but still new entities are not added
correctly.

What is the minimum of the code I need to write to make this simple CRUD
example working?



Thanks!


Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top