WPF和实体框架代码第一 [英] WPF and entity Framework code first
问题描述
我想使用数据网格和保存按钮来实现一个简单的WPF。
当我点击保存按钮它将接受更改(行编辑,单元格编辑,新行,删除等)
我试过 RowEditHandler
和 CollectionChange
使用observable集合的事件。但我不能得到一个解决方案。任何人都可以给我一个简单的方法。
使用数据集(xsd),我能够通过发送网格数据文本到数据集并使用更新功能来获取该simpy。
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 anyone 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.
感谢您的帮助
推荐答案
ADO.NET团队博客举例说明如何将Entity Framework Code-First模型绑定到WPF DataGrid,该WPF DataGrid支持添加,删除并在网格中编辑实体,最后保存所有更改。它集中在一个Master-Details方案,但是通过一些修改也可以使用一个简单的DataGrid:
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:
该示例基于EF CTP5,但是最有可能在新版本的EF 4.1 RC版本中也可以使用。
The example is based on EF CTP5 but it will most likely also work without changes with the new EF 4.1 RC version.
ADO.NET团队示例使用代码隐藏文件和事件。如果您希望严格使用MVVM方法,则在此答案中提供的David Veeneman的解决方案可能会有所帮助:
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:
这不是一个完整的WPF示例但可以作为扩展ObservableCollection的一个基础,它支持使用Entity Framework创建更新删除操作。
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.
这篇关于WPF和实体框架代码第一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!