验证问题。 [英] Validation Issue.
问题描述
DataAnnotations不适用于好友类。以下代码始终验证为true。为什么?
var varValid = Validator.TryValidateObject(customer,Context,results,true);
这里是伙伴类。
公共部分类客户
{
公共字符串名称{get;组; }
public int Age {get;组; }
}
[元数据类型(typeof(CustomerMetaData))]
公共部分类客户
{
类CustomerMetaData
{
[必需(ErrorMessage ="您必须为客户提供名称。)]
public string Name {get;组; }
}
}
你好,
欢迎光临ADO.NET实体框架和LINQ to Entities论坛!
我认为你在.NET 4.0或Silverlight 3中使用Validator.TryValidateObject方法, http://msdn.microsoft.com/en-us/library/d d411772(VS.100).aspx 。 您能否向我们提供有关此问题与实体框架相关的更多信息?
此外,对于EF 4问题,请在预发布论坛上发帖以获得更好的支持,因为它仍然处于预发布状态, http://social.msdn.microsoft.com/Forums/en-US/ adonetefx / threads 。
度过愉快的一天!
最诚挚的问候,郎灵芝
MSDN订阅者支持 in Fo朗姆酒
如果您对我们的支持有任何反馈,请联系 msdnmg@microsoft.com 跨度> 跨度>
DataAnnotations does not work with buddy class. the following code always validate true. Why ?
var isValid = Validator.TryValidateObject(customer, Context, results, true);
and here is the buddy class.
public partial class Customer { public string Name { get; set; } public int Age { get; set; } } [MetadataType(typeof(CustomerMetaData))] public partial class Customer { class CustomerMetaData { [Required(ErrorMessage = "You must supply a name for a customer.")] public string Name { get; set; } } }
Hello,
Welcome to ADO.NET Entity Framework and LINQ to Entities forum!
I think you are using the Validator.TryValidateObject method in .NET 4.0 or Silverlight 3, http://msdn.microsoft.com/en-us/library/dd411772(VS.100).aspx. Could you please provide us with more information about how this question is related to Entity Framework?
Besides, for EF 4 issues please post in the pre-release forum for better support, since it is still in pre-release status, http://social.msdn.microsoft.com/Forums/en-US/adonetefx/threads.
Have a nice day!
Best Regards,
Lingzhi SunMSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
这篇关于验证问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!