开发者

Using DataAnnotations and attributes in Model First development

开发者 https://www.devze.com 2023-02-26 20:18 出处:网络
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 mo

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消