views:

293

answers:

4

I am trying to convert my model-first project to code-first, as I can see dealing with the models with the graphical designer will become hard. Unfortunately, with all my googling I can't find one good reference that describes how to do code-first development. Most resources are out of date (so out of date they refer to it as code-only), and the other references I can find seem to assume you understand the basics of context building and code-first (for example, they reference code to build contexts but don't describe where that code should actually go, and how it's actually run).

Are there any decent resources for code-first development, that describe how to map your POCO entities into a database schema?


Edit: Ok well, I give up on code first for now. The getting started document I linked to in my answer seems to have some flaws in it (for example, some details of context building and the EntityConnection dbConnection type, and some of the relationship mapping code does not compile they way they have written it). I spent 2 days trying to find any way to get this to work, and I got close (I think) but ultimately failed with google completely being unhelpful.

As of right now, I think it's more productive for me to keep going with Model first development, and hope that by the time the edmx becomes awkward code-first is no longer in CTP state, and has better (as in some that actually exists) documentation.

I am marking the answer on POCOs as the correct one, as while it isn't actually code-first, if you want to have entities in code it is probably the best bet, even though it requires a database and an EDMX generated from it before it will work.

+2  A: 

Well it seems I've gotten a bit closer.

It seems like Code-First was not included in the final released version of VS2010. Thus in order to use it you have to download the Entity Framework CTP 3 at http://www.microsoft.com/downloads/details.aspx?FamilyID=af18e652-9ea7-478b-8b41-8424b94e3f58&displayLang=en. That seems to be the latest CTP for EF.

After installing that you must add a reference to Microsoft.Data.Entity.CTP.

Finally, that CTP download page brought me to http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx. While the date on the page was June of 2009, it claims it's been updated and the CTP (released in Feb) points to it so it might still be accurate. I'll play with it tomorrow to see how accurate it really is.

KallDrexx
@KallDrexx: Any success with this?
Eric J.
Nope :(. The examples in the getting started doesn't work right for me and I couldn't figure it out. Thus I decided to go back to model first until there is up to date and working docs on it.
KallDrexx
+1  A: 

this maybe what your after.

Effectively you just use your EF model to define the mappings to the DB and not to generate classes, and create a context to link your objects to the DB through the EF model mappings.

grrrrrrrrrrrrr
+2  A: 

Enjoy the new greatest EF CTP 4. There is a lot of new improvements and some good resources to learn a lil bit more.

http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4announcement.aspx

http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4piwalkthrough.aspx

http://blogs.msdn.com/b/adonet/archive/2010/07/14/ctp4codefirstwalkthrough.aspx

Kim Tranjan
Awesome thanks for the links. I'm still going to hold off since they say there could still be API changes but it's good to prepare for!
KallDrexx