EF Model First or Code First Approach?

后端 未结 4 1711
情歌与酒
情歌与酒 2020-12-04 10:38

I know this question has been asked numerous times before as I’ve read quite a few posts on the topic about the pros and cons etc but I still can’t decide which approach is

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 10:52

    I’ve looked at both approaches and I do favour Entity Model approach only because I like simplicity of the designer and I like seeing the whole model in front me, it shows the overall picture in one snapshot. Also, me not being a strong programmer I am impressed with the way it generates the POCO’s using the DbContext generator template and does all the linking between the classes.

    +

    Mapping entities to the database via configuration classes I find impossible :).

    = use model first

    If it’s good practice to create buddy classes why can’t I find many tutorials showing this for MVC 3? Are Buddy Classes another name for View Models? And why can’t I find any tutorials by Microsoft showing these buddy/view models in use with MVC 3?

    This might be because the code-first is something like a new kid in the block. That's why there are mostly code-first tutorial for MVC3. Model-first is 'much' older and was probably most favourited solution in times of MVC2.

    Btw: You already know my oppinion, that you should use, what you like best or find most comfortable (as I told you last time you asked about this), but I just wanted to add something here :)

    Edit after comments:

    Take a look at these things, that will help you with code first a lot imo:

    Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10) Scaffold your ASP.NET MVC 3 project with the MvcScaffolding package

    ++ these great videos from MIX11 at channel9:
    Scott Hanselman showing new stuff in his awesome way as usually
    Steve Sanderson showing power of MvcScaffolding

提交回复
热议问题