0
我已经使用企业库验证机制读取并搜索了此问题。这个非常简单的表单应用程序演示了该问题元数据类被验证器忽略。我正尝试在一个实体框架的MVC应用程序中使用它。.Net 3.5元数据类型在使用验证器时被忽略
这是在.net 3.5中使用VS 2008在XP SP3上。
namespace ValidationTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string longname = "this is much too long to be a name";
Customer2 cust = new Customer2(longname);
ValidationResults r = Validation.Validate<Customer2>(cust);
if (!r.IsValid)
{
throw new ArgumentException();
}
}
}
public partial class Customer2
{
public string CustomerName;
public Customer2(string name)
{
CustomerName = name;
}
}
[MetadataType(typeof(CustMetadata))]
public partial class Customer2
{
}
public class CustMetadata
{
[StringLengthValidator(0, 20)]
public string CustomerName { get; set; }
}
}
它们都在同一个文件中用于演示目的。如果我将StringLengthAttribute移动到主类,它确实有效。
任何有识之士将不胜感激。
感谢
谢谢 - 我尝试过,仍然没有去。 – Jerry 2010-08-21 12:47:06
@Jerry - 我复制了你的代码示例,它工作正常(它抛出一个ArgumentException)!我能想到的唯一的事情就是您使用的不是Enterprise Library 5.您可以使用EL 4.1吗? – 2010-08-21 14:10:14