Update Model From Database (Database First)

前端 未结 4 1040
暖寄归人
暖寄归人 2020-12-16 06:08

I\'m using MVC3 VS2010 with EF4.1, I have created my DB using SQL Server and I import it to the MVC3 Web Application.

I have a challenge here, when I come to Update

4条回答
  •  忘掉有多难
    2020-12-16 06:47

    The first rule of any designer is: It it generates any code you can't modify it because it will be completely deleted next time you update anything in the designer.

    All generated classes are partial so you can create your own partial part and put your custom logic there. You obviously can't add attributes to properties defined in auto generated part. In case of data annotations it is possible either through buddy classes or by custom T4 template which will contain your own logic to decide which data annotation should be added during code generation. Both scenarios are mostly considered as a bad practice because you should have separate view model per view with validation needed exactly for that view.

提交回复
热议问题