验证与ASP.NET MVC LINQ to SQL的:我怎么避免编辑生成的源? [英] Validation with ASP.NET MVC Linq To SQL: how do I avoid editing a generated source?

查看:158
本文介绍了验证与ASP.NET MVC LINQ to SQL的:我怎么避免编辑生成的源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读上几个验证文档的 ASP.NET MVC 。忽略那些建议另起炉灶编写自己的验证逻辑,大多数文章主张用 XVAL 或数据注释验证器,它们都允许通过装饰模型的性能声明式验证(*)。

I'm reading several docs on validation in ASP.NET MVC. Ignoring those that suggest to reinvent the wheel writing your own validation logic, most articles advocate the use of xVal or Data Annotation Validators, both of which allow declarative validation through decorating models' properties(*).

我想我会去为 XVAL ,因为它似乎是最建议的(因此,我希望支持)。令我百思不解的是,我使用 LINQ到SQL ,我的模型自动生成的文件中声明( DBML + partial.cs ),包含几个类和近5000线长,所以我不是很急于对它进行编辑,如果我更改了数据库结构,我会必须重新生成它,失去我的变化。

I think I'll go for xVal, as it seems to be the most suggested (and thus, I hope, supported). What puzzles me is that I'm using Linq to SQL, and my models are declared in an automatically generated file (dbml + partial.cs), containing several classes and almost 5000 lines long, so I'm not very eager to edit it, as if I change the db structure I'll have to regenerate it, loosing my changes.

有没有办法来避免编辑该文件?

Is there a way to avoid editing that file?


(*)我还发现一个验证工具包这也提供了声明式验证和没有按'T的要求来装饰模型的属性,但页面显示57下载,所以如果该项目成熟与否我不能告诉。

(*) I've also found a Validator Toolkit which also provides declarative validation and doesn't request to decorate models' properties, but the page shows 57 downloads, so I can't tell if the project is mature or not.

推荐答案

您可以创建一个部分类,并添加注释的数据校验的部分类这样,如果你的dbml文件重新生成也没关系。

You can create a partial class and add the Data Annotation Validators to the partial class that way it doesn't matter if your dbml file is regenerated.

试试这个 asp.net文章和<一个href=\"http://rachelappel.com/asp-net-dynamic-data/custom-validation-in-asp-net-dynamic-data-using-attributes/\"相对=nofollow>这篇文章

这篇关于验证与ASP.NET MVC LINQ to SQL的:我怎么避免编辑生成的源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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