使用MVC3中的实体框架验证模型实体 [英] Validation on model entities with entity framework in MVC3

查看:69
本文介绍了使用MVC3中的实体框架验证模型实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用带有Razor引擎视图的Entity Framework在MVC3中创建一个小应用程序。现在我想验证模型的实体,但我不知道如何。我在google上搜索了这个,但无法找到确切的解决方案。

As Entity Framework自动创建了模型类,所以我如何使用DataAnnotations进行模型实体验证?

请帮帮我如果你有一个合适的解决方案。

Hi,
I am creating a small application in MVC3 using Entity Framework with Razor engine view. Now i want to validate entities of model but i don't know how. I have searched this on google also but unable to find exact solution.
As Entity Framework automatically created model classes so how i use DataAnnotations for model entities validation?
Please help me to get a proper solution if you have.

推荐答案

查看本教程: http://www.asp.net/mvc/tutorials/older-versions/models-(数据)/ validation- with-the-data-annotation-validators-cs [ ^ ],特别是使用带有实体框架的数据注释验证器

主要思想是使用部分类来添加DataAnnotation属性。
Check this tutorial: http://www.asp.net/mvc/tutorials/older-versions/models-(data)/validation-with-the-data-annotation-validators-cs[^], especially section Using Data Annotation Validators with the Entity Framework.
The main idea is using partial classes to add DataAnnotation attributes.


检查以下链接,了解如何验证您r POCO课程?模特



http://www.codeguru.com/csharp/article.php/c20103/Learn-How-to-Validate-Your-Entities-in-the -Entity-Framework.htm

[ ^ ]

http://msdn.microsoft.com/en-us/data/gg193959.aspx [ ^ ]



< a href =http://codetunnel.com/blog/post/validation-with-entity-framework> http://codetunnel.com/blog/post/validation-with-entity-framework [< a href =http://codetunnel.com/blog/post/validation-with-entity-frameworktarget =_ blanktitle =New Window> ^ ]



希望这有助于
Check the below links which gives an idea on how to validate your POCO classes?models

http://www.codeguru.com/csharp/article.php/c20103/Learn-How-to-Validate-Your-Entities-in-the-Entity-Framework.htm
[^]
http://msdn.microsoft.com/en-us/data/gg193959.aspx[^]

http://codetunnel.com/blog/post/validation-with-entity-framework[^]

Hope this helps


这篇关于使用MVC3中的实体框架验证模型实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆