Question

I haven't followed the ASP.NET MVC evolution since version 3 or so. Back then in MVC3 the simplest/preferred way to boost entity metadata info for the MVC DisplayNameFor etc magic was to use DataAnnotations. With the possible use of the [MetadataType] attribute if the classes were code generated.

I am wondering if this is still the preferred approach in MVC 5 (reading through what's news for V4 and V5 did not reveal any specific) or there are now some more customizable (built in) metadata engines around.

The genuine problem of mine is how to annotate entity classes in a different assembly. My project is built on a way where EDMX files and thus entity classes are living in a separate assembly (reused by the Web, PowerShell, etc modules of the project)

Was it helpful?

Solution

For the most, yes, data annotations are still the way to go, but since you're dealing with third-party classes, your best bet is looking into the nuget package, FluentValidation. It allows you to configure validation on your class properties via a code-based API, instead of having to directly add annotations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top