views:

25

answers:

1

Hello

I currently have a resource-file where I store "errormessages". And I would like to change it so it uses database. I have functions that returns from database. Whats needed to do more in my class besides the "retrieve-error"-part to use it like I did before:

[Required(ErrorMessageResourceType = typeof(ErrorMessages), ErrorMessageResourceName = "SurnameRequired")]

Not sure how it all gets passed to my class etc...

Any pointers would be useful

/M

+1  A: 

DataAnnotations does not have another mechanism to fetch localized error messages from a resource, but you can change the internal implementation of your ErrorMessages type to fetch messages from a database:

public static class ErrorMessages
{
    public static string SurnameRequired
    {
        get { return LoadLocalizedMessage("SurnameRequired"); }
    }

    private static string LoadLocalizedMessage(string key)
    {
        var culture = CultureInfo.CurrentCulture;

        // Query the database or some local cache.
    }
}
Steven