MetadataType-Problem

Ich verwende VS2008 SP1, WCF Ria Service Juli 2009 CTP. Ich habe herausgefunden, dass MetadataType im Teilklassenmodus nicht funktioniert. Ich weiß wirklich nicht, was ich verpasst habe:

Arbeit:-

public partial class Person
{
    private string _Name;

    [Required(AllowEmptyStrings=false, ErrorMessage="Name required entry")]
    [StringLength(3)]
    public string Name
    {
        set{_Name = value;}
        get{return _Name;}
    }
}

class Program
{
    static void Main(string[] args)
    {
        Person p = new Person { Name="123432" };
        List res = new List();
        Validator.TryValidateObject(p,new ValidationContext(p,null,null),
            res,true);
        if (res.Count > 0)
        {
            Console.WriteLine(res[0].ErrorMessage);
            Console.ReadLine();
        }
    }
}

Nicht arbeiten

public partial class Person
{
    private string _Name;

    public string Name
    {
        set{_Name = value;}
        get{return _Name;}
    }
}

[MetadataType(typeof(PersonMetadata))]
public partial class Person
{
}


public partial class PersonMetadata
{
    [Required(AllowEmptyStrings=false, ErrorMessage="Name required entry")]
    [StringLength(3)]
    public string Name;
}

class Program
{
    static void Main(string[] args)
    {
        Person p = new Person { Name="123432" };
        List res = new List();
        Validator.TryValidateObject(p,new ValidationContext(p,null,null),
            res,true);
        if (res.Count > 0)
        {
            Console.WriteLine(res[0].ErrorMessage);
            Console.ReadLine();
        }
    }
}

Antworten auf die Frage(3)

Ihre Antwort auf die Frage