开发者

WPF and entity Framework code first

I would like to implement a simple WPF with a datagrid and a save button. when I click save button it will accept changes (row edit,cell edit, new row, delete etc) I tried RowEditHandler and CollectionChange event using observable collections. But I couldnt get a soluton. Can anyon开发者_如何学JAVAe please show me a simple way. Using dataset (xsd), I was able to achive that simpy by sending datacontext of grid to dataset and using update function.

thanks for help


The ADO.NET team blog has an example how to bind a Entity Framework Code-First model to a WPF DataGrid which supports adding, deleting and editing entities in the grid and finally saving all changes. It is focussed on a Master-Details scenario but should with a few modifications also work in your even simpler case with only a single DataGrid:

http://blogs.msdn.com/b/adonet/archive/2011/03/08/ef-feature-ctp5-code-first-model-with-master-detail-wpf-application.aspx

The example is based on EF CTP5 but it will most likely also work without changes with the new EF 4.1 RC version.

The ADO.NET team example uses code-behind files and events. If you prefer to strictly work with the MVVM approach the solution of David Veeneman provided in this answer might be helpful:

Entity Framework 4 and WPF

It's not a full WPF example but can serve as a foundation how to extend an ObservableCollection in a way that it supports Create-Update-Delete operations with Entity Framework.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜