Using DataAnnotations and attributes in Model First development
I have been developing my Models "model-first" by using the EDMX designer. I'm rather fond of it, but wondering how I can use this process to apply attributes, specifically DataAnnotations, to my model classes like so:
<DisplayFormat(ApplyFormatInEditMode:=True, DataFo开发者_如何学PythonrmatString:="{0:d}")>
I'm guessing that if I type those manually onto my model classes it will get overwritten whenever I update my EDMX file. What is the correct process here?
Thanks!
At the risk of repeating myself formatting attributes such as DisplayFormat
should be applied to the view models and not the models. Models contain reusable business logic. View models on the other hand are specifically designed for a given view, so the formatting should be done on those view models. A controller always passes a view model to a view.
精彩评论