简体   繁体   English

实体框架6使用WPF建模第一次数据验证

[英]Entity Framework 6 Model First Data Validation with WPF

I've been searching all over trying to find a reasonable and working solution to this. 我一直在寻找一个合理且有效的解决方案。

I've created a new Database using EF6.0 (VS 2013) using a Model First approach. 我使用Model First方法使用EF6.0(VS 2013)创建了一个新数据库。 This model was created in the WPF application that will utilize the database. 此模型是在将使用数据库的WPF应用程序中创建的。 I have been unable to successfully implement any type of data validation (I've done data annotations in ASP and EF, metadata classes etc), however, I've been unable to get my meta data classes to be utilized. 我无法成功实现任何类型的数据验证(我已经在ASP和EF中完成了数据注释,元数据类等),但是,我一直无法使用我的元数据类。

Does anyone have any straightforward write-up/article/blog/etc that has a firm and VALID example of how to use EF6 Data Validations to drive notifications to the UI in a WPF application? 有没有人有任何直截了当的文章/文章/博客/等有一个公司和VALID示例如何使用EF6数据验证来驱动WPF应用程序中的UI通知? Any assistance would helpful, or perhaps, better advice on data validation. 任何帮助都会对数据验证有所帮助,或者更好。 I could easily write custom validation logic to check the entity before attempting to persist to the database, but this seems counter intuitive to the idea of the Entity Framework and its built in validation attributes. 在尝试持久化到数据库之前,我可以轻松地编写自定义验证逻辑来​​检查实体,但这似乎与实体框架及其内置验证属性的想法相反。

Are your mapping files created using Fluent API or data annotations? 您的映射文件是使用Fluent API还是数据注释创建的?

Maybe you can implement IValidatbleObject interface, or you may use the FluentValid library. 也许你可以实现IValidatbleObject接口,或者你可以使用FluentValid库。

Check this answer How do I use IValidatableObject? 检查此答案如何使用IValidatableObject? .

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM