Question: There's a way to set the default resource to the data annotations validations?

I don't wanna make something like this:

```
[Required(ErrorMessage="Name required.", ErrorMessageResourceType=typeof(CustomDataAnnotationsResources)]
public string Name { get; set; }

```

I would like something like this:

**Global.asax**

```
DataAnnotations.DefaultResources = typeof(CustomDataAnnotationsResources);

```

then

```
[Required]
public string Name { get; set; }

```

someone gimme a light!

thanks in advance

**EDIT**

My real problem was with EF Code First CTP4. CTP5 fix it. Thanks for everyone.

Answer: 
To achieve this, I created a new class that inherits from RequiredAttribute, and the error message is embedded inside this new class:

```
public class RequiredWithMessageAttribute : RequiredAttribute
{
    public RequiredWithMessageAttribute()
    {
        ErrorMessageResourceType = typeof(ValidationResource);
        ErrorMessageResourceName = "RequiredErrorMessage";
    }
}

```

The error message is taken from the ValidationResource.resx file, where I list the error message as follows:

RequiredErrorMessage --> "{0} is required."

where {0} = display name.

I then annotate my models like this, so I never have to repeat my error message declarations:

```
[RequiredWithMessage]
public string Name { get; set; }

```

Once you do this, an error message ("Name is required.") will appear whenever validation fails.

This works properly with ASP.NET MVC's server-side validation and client-side validation.
I did another approach. It still needs you to inherit `DataAnnotation` attributes, but you can get a more flexible translation solution.

Code from [my blog post](http://blog.gauffin.org/2010/11/simplified-localization-for-dataannotations/) (read it fore more details)

**End result**

```
public class User
{
    [Required]
    [LocalizedDisplayNameAttribute("User_Id")]
    public int Id { get; set; }

    [Required]
    [StringLength(40)]
    [LocalizedDisplayNameAttribute("User_FirstName")]
    public string FirstName { get; set; }

    [Required]
    [StringLength(40)]
    [LocalizedDisplayNameAttribute("User_LastName")]
    public string LastName { get; set; }
}

```

**1 Inherit all data annotation attributes like this**

```
public class RequiredAttribute : System.ComponentModel.DataAnnotations.RequiredAttribute
{
    private string _displayName;

    public RequiredAttribute()
    {
        ErrorMessageResourceName = "Validation_Required";
    }

    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        _displayName = validationContext.DisplayName;
        return base.IsValid(value, validationContext);
    }

    public override string FormatErrorMessage(string name)
    {
        var msg = LanguageService.Instance.Translate(ErrorMessageResourceName);
        return string.Format(msg, _displayName);
    }
}

```

**2 Inherit DisplayNameAttribute**

```
public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
    private PropertyInfo _nameProperty;
    private Type _resourceType;

    public LocalizedDisplayNameAttribute(string className, string propertyName)
        : base(className + (propertyName == null ? "_Class" : ("_" + propertyName)))
    {

    }

    public override string DisplayName
    {
        get
        {
            return LanguageService.Instance.Translate(base.DisplayName) ?? "**" + base.DisplayName + "**";
        }
    }
}

```

**3. Create the language service (you can switch to any language source in it)**

```
public class LanguageService
{
    private static LanguageService _instance = new LanguageService();
    private List<ResourceManager> _resourceManagers = new List<ResourceManager>();

    private LanguageService()
    {
    }

    public static LanguageService Instance { get { return _instance; } }

    public void Add(ResourceManager mgr)
    {
        _resourceManagers.Add(mgr);
    }

    public string Translate(string key)
    {
        foreach (var item in _resourceManagers)
        {
            var value = item.GetString(key);
            if (value != null)
                return value;
        }

        return null;
    }
}

```

**Finally you need to register the string tables you use to translate the validation messages and your models**

```
LanguageService.Instance.Add(MyNameSpace.ModelResource.ResourceManager);
LanguageService.Instance.Add(MyNameSpace.ValidationResources.ResourceManager);

```