将数据注释验证器与实体框架结合使用
我正在开发使用实体框架和 POCO 类的 WPF 应用程序。我想在 UI (WPF) 中使用 POCO 类的数据注释进行客户端验证。由于我无法修改 POCO 类(它将在更新实体模型后重新生成),因此,我按照文章中提到的方法使用部分类实现了数据注释: http://www.asp.net/mvc/tutorials/validation-with-the- data-annotation-validators-cs 位于“在实体框架中使用数据注释验证器”部分。不知何故,这种方法在我的情况下不起作用。有人可以建议我如何在实体框架中使用数据注释吗?
I am working on WPF application which uses Entity Framework alongwith POCO classes. I would like to use data annotations with POCO classes for Client side validations in UI (WPF). Since, I can't modify the POCO classes (it will be regenerated after updating the entity model), therefore, I have implemented the data annotations using partial class as per approach mentioned in the article: http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs under section "Using Data Annotation Validators with the Entity Framework". Somehow this approach is not working in my case. Can anybody suggest something as to how can I use data annotation with Entity Framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以查看 WPF 应用程序框架 (WAF)< 的 BookLibrary 示例应用程序/a>。它展示了如何在实体框架中使用数据注释。它展示了如何在 WPF 中使用它以便显示验证错误。
You might have a look at the BookLibrary sample application of the WPF Application Framework (WAF). It shows how to use data annotations with the Entity Framework. And it shows how to consume it in WPF so that the validation errors are shown.
无需注册数据注释。只需按照文章中提到的步骤进行即可现在正在工作。
There is no need to registered the Data Annotations. Just followed the steps mentioned in the article & its working now.