2

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)

Peter Aron Zentai
  • 11,482
  • 5
  • 41
  • 71
  • What about creating `ViewModel` classes for your EF class and add dataannotations to ViewModel class? – Murali Murugesan Feb 25 '14 at 16:33
  • That is no go :( We have over 250 entities... – Peter Aron Zentai Feb 25 '14 at 16:35
  • 1
    well the whole point on MVC is to separate your models from your view models thus MVVM...so yes, the point is that it seems that you would be duplicating the work but not quite since your view will have a view-model which is almost based on your model but view specific data – Ahmed ilyas Feb 25 '14 at 17:55
  • I dont need another model for the CRUD scenarios. What I need is to be able to localize field names - then let the scaffolding and ASP.NET MVC templates do the heavy lifting. – Peter Aron Zentai Feb 25 '14 at 18:42

1 Answers1

1

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.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444