views:

70

answers:

3

The Entity Framework 4.0 Futures preview (CTP3 now) has a code only modeling paradigm for mapping between your types and the database. No edmx files involved and no EDM designer needed.

I wanted to know what are the big advantages of Code Only vs Model First? What can be done in Code First which can't be done in other models (Model First & database first)? I am thinking maybe more control but I cant still modify the CSDL, SSDL, MSL files and my own code to get the result I need. The Code Only model involves doing everything in code which could be prone to errors like producing the wrong desired model or missing property definitions.

+3  A: 

It is really a matter of preference. Quoting the EF design blog:

However many developers view their Code as their model.

Ideally these developers just want to write some Domain classes and without ever touching a designer or a piece of XML be able to use those classes with the Entity Framework. Basically they want to write 'Code Only'.

http://blogs.msdn.com/b/efdesign/archive/2009/06/10/code-only.aspx

Yakimych
A: 

Based on my experience, I would go for Model-First because it allows you model your domain in such complicated ways that to do in Code-First would be challenging. In fact there would be several advance modeling scenarios which you won't be able to achieve in the first version of the code first. This is strictly my thinking based on my understanding of how complicated modeling could get. But until EF team finalizes on Code-First, we won't know.

Also if you came from linq to sql world, you would be shocked to see good the Entity Model Designer is. It works really great and can let you build complicated model with very little effort on the developer side.

zeeshanhirani
A: 

One immediate advantage of this is that if you are currently writing partial classes to add methods or data annotations to your entities, you can now have your model definition and methods all in one place. If the model becomes complicated over time, it can be hard to keep straight everywhere you need to touch to when you need to add a new field, make sure it's validated, and add logic with it.

aubreyrhodes