0

I have a Winforms application using EF4 database 1st approach (having .edmx file for data access), now i need a bidirectional dataviewgrid which enables me to show, modify, delete and add columns to the database table, showing the data seems to be easy and can be done using the wizard alone, but to write data back into the database is the complex part, i found lots of threads regarding this issue but non of them was envolving the EF4 components to access the data (if possible at all), the most examples use a datase / datasource / bindingnavigator /bindingcontext and more confusing stuff.

the Question is do i really need all these components? or can i use my object model to do this?

It would be great if anyone can provide some clarification on how all these objects work together, any good links or small code parts are welcome too.

Thanks in advance

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130

2 Answers2

0

The DataGridView is just a View from your Data. You should write a Class where each Column in your Table is represented by an Propertie. Then load all Data from your Table in an Objectlist (List). Add a UpdateMethod to your class. Now you can read/change Datas in the GridView and automaticly your Object Properties will be changed. After clicking save Button or something you call the Update Method for all Objects in your List. So you can editing Datas in GridView and save it to your DataBase

Sebi
  • 3,879
  • 2
  • 35
  • 62
0

Here is the answer linked by @RobertHarvey:

The problem with the line:

select new { c.UserName, c.Password, c.Description }

Is that it is creating an anonymous type, and anonymous types are immutable - that is read only. This is why your changes do not get reflected in either the new type or in the original EF object.

Now, as for ways of not showing all the columns of the object you are binding to, I've given three options below.

Community
  • 1
  • 1
CloudyMarble
  • 36,908
  • 70
  • 97
  • 130