验证 EntityFramwork 4.0 类的最佳方法是什么?
我已经进行了大量搜索,但尚未找到一种简单的方法来验证通过 WCF 数据服务通过线路传递的 EntityFramework 4.0 实体。基本上,我想在客户端上做一些事情,例如:
Proxy.MyEntities entities = new Proxy.MyEntities(
new Uri("http://localhost:2679/Service.svc"));
Proxy.Vendor vendor = new Proxy.Vendor();
vendor.Code = "ABC/XYZ";
vendor.Status = "ACTIVE";
// I'd like to do something like the following:
vendor.Validate();
entities.AddToVendors(vendor);
entities.SaveChanges();
在这方面的任何帮助将不胜感激!
I've done a fair amount of searching but I've yet to find an easy way to validate EntityFramework 4.0 entities passed accross the wire via WCF Data Services. Basically, I want to do something on the client like:
Proxy.MyEntities entities = new Proxy.MyEntities(
new Uri("http://localhost:2679/Service.svc"));
Proxy.Vendor vendor = new Proxy.Vendor();
vendor.Code = "ABC/XYZ";
vendor.Status = "ACTIVE";
// I'd like to do something like the following:
vendor.Validate();
entities.AddToVendors(vendor);
entities.SaveChanges();
Any help in this regard would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我是你,我会使用 System.ComponentModel.DataAnnotations 框架。
网络上有很多例子。
您可以使用 ValidationAttributes(如必需、范围等)并创建自己的属性来执行自定义验证。
请参阅下文如何验证实体。
我希望这对您有帮助,如果您需要任何其他信息,请询问
有关
丹尼尔
If I were you I would use the System.ComponentModel.DataAnnotations framework.
There are many examples on the web for it.
You can use the ValidationAttributes like required, range etc and create your own attribute to perform custom validation.
See below how to validate an entity.
I hope this helps if you need anything else just ask
Regard
Daniel