views:

914

answers:

4

Hi folks,

i'm under the impression that

  • EF with POCO: allows you to map your own POCO's to the entities on the model (.edmx).
  • EF Code-Only: no edmx / model designer (ie. CSDL/SSDL/MSL (collectively EDMX) metadata). Still POCO's but the mappings, relationships, navigation, etc are all manually coded (hence the code-only, description).

If this description of the two concepts is (more or less) correct, why would someone what to do a Code-Only instead of EF with POCO?

Both are doing POCO's, but the 2nd one has the extra burden of having to also do the mapping, manually?

+3  A: 
  1. Code only is great if you want to write the mapping by hand without having to slog through XML. Also the edmx designer gets unwieldy after 50 or so models, it's just a burden to use that way.

When something goes wrong inside your mapping XML its really a PITA to dig around in the xml to make the fixes you need. Also the designer breaks if you start manually editing your xml in certain scenarios.

Now I don't know the details but the designer in EF1 didn't support all the available mapping options. The EF4 designer has some improvements ( one way relationships come to mind ) but I'm not sure if it has feature parity with manual mappings.

  1. Yes.
jfar
+3  A: 

The only thing I would add to jfar's answer is that with Code-Only you don't have to create mappings.

Mappings can be inferred by convention most of the time.

Alex James
Can you please give an example?
Pure.Krome
Check out the Code-Only walk thru on blogs.msdn.com/adonet
Alex James
A: 

I don't think that Code-Only presently lets you pregenerate views, so there may be a performance cost. This might change before release, though.

Craig Stuntz
You can always extract the EDMX and pre-generate the views off that once you are ready to deploy etc. –
Alex James
A: 

Something else that has not been mentioned is that you get full compile-time checking of your syntax when using Code Only. If you are using the visual designer with EDMX, you get some compile-time checking, but it is limited. For larger models, EDMX gets extremely unweildy, and manually writing the CSDL, SSDL, and MSL is the only decent way to manage extremely large models with XML mappings. You don't get any compile-time checking if you manually manage your mappings.

With Code Only, you have the benefit of complete compile time checking for models of any size, even if you have hundreds or thousands of entities you need to work with. It also results in less "clutter", as your end product is all compiled assemblies, rather than a mix of assemblies and various kinds of xml files.

jrista