views:

3608

answers:

6

Hi,

I've been programming for a while and have used LINQ-To-SQL and LINQ-To-Entities before (although when using entities it has been on a Entity/Table 1-1 relationship - ie not much different than L2SQL)

I've been doing a lot of reading about Inversion of Control, Unit of Work, POCO and repository patterns and would like to use this methodology in my new applications.

Where I'm struggling is finding a clear, concise beginners guide for EF4 which doesn't assume knowledge of EF1.

The specific questions I need answered are:

Code first / model first? Pros/cons in regards to EF4 (ie what happens if I do code first, change the code at a later date and need to regenerate my DB model - Does the data get preserved and transformed or dropped?)

Assuming I'm going code-first (I'd like to see how EF4 converts that to a DB schema) how do I actually get started? Quite often I've seen articles with entity diagrams stating "So this is my entity model, now I'm going to ..." - Unfortunately, I'm unclear if they're created the model in the designer, saved it to generate code then stopped any further auto-code generation -or- They've coded (POCO)? classes and the somehow imported them into the deisgner view?

I suppose what I really need is an understanding of where the "magic" comes from and how to add it myself if I'm not just generating an EF model directly from a DB.

I'm aware the question is a little vague but I don't know what I don't know - So any input / correction / clarification appreciated.

Needless to say, I don't expect anyone to sit here and teach me EF - I'd just like some good tutorials/forums/blogs/etc. for complete entity newbies

Many thanks in advance

+1  A: 

Here's a walkthrough on the POCO Template for the Entity Framework that looked pretty good. You might also want to check out the ADO.NET team blog. If you want to start at the beginning(EF v1.0) as a base for your EF knowledge, I found Julia Lerman's Programming Entity Framework book very complete.

DaveB
Thanks - I hadn't seen the book but I've read both the links provided. The Template walkthrough is useful in explaining how additional functionality can be added to POCO objects once they're defined (eg Lazy loading) but (and I may be missing something obvious here) it doesn't actually explain how to get started (ie simply creating a class as specified doesn't make it an entity nor associate it with a model)I've had a similar experience with the blog. I will consider getting the book though - It looks promising - Thank you.
Basiclife
Regarding the book of Julia Lerman it's worth to be mentioned that she is working on a second edition covering EF4: http://learnentityframework.com/LearnEntityFramework/book/here-i-go-again-programming-entity-framework-2nd-edition-for-ef4/ . I remember that I've read somewhere that the planned publish date is in May this year but I can't find the source anymore. Also I just found this site: http://www.nakedobjects.net/home/index2.shtml
Slauma
Slauma, the link you provided looked ike exactly what I need - except it's using a 3rd party "Naked Obects" library which seems to be obfuscating the complexity somehow - For a minute, I thought you'd cracked it
Basiclife
+2  A: 

You can take Lerman's book or something simplier like "Pro linq object-relational mapping". All concepts are still the same with POCO, except that now you should disable code generation and map directly to your model in edmx csdl (or create your own POCO generator). All mapping principles are the same also. Anyhow in run time you are working with proxy which is derived from your POCO object so you should concern about interception support (virtualization of your POCO properties).

Voice
+5  A: 

I've come across this: http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx

Which gives you step-by-step for code first. It does require the CTP 3 for EF4 (Download linked from that article).

This is pretty close to what I was after (although ideally a solution that doesn't rely on a CTP would've been preferable)

Basiclife
+2  A: 

I do recommend that you take a half hour or so and generate a stable EF1.0 model in your current VS. That will get you a long way towards understanding the metaphors and concepts of EF 4.0. Just whip up a simple Customer, Products and Orders db...I recommend doing your own and not using Northwind.

Chris B. Behrens
+2  A: 

Hi,

There's also:

http://daniel.wertheim.se/2010/05/16/entity-framework-4-ctp3-code-first-vs-linq-to-sql/

and

http://daniel.wertheim.se/2009/12/20/updates-to-putting-entity-framework-4-to-use-in-a-business-architecture/

//Daniel

Daniel
Really detailed - Wish I'd seen that a month ago. Many thanks
Basiclife
His project structure looks just like an old nHibernate based project I was working on. Cept for all the WCF jazz, which I am keen on refreshing myself on. Solid link.
Merritt
+4  A: 

These articles might be of interest...the series really gets into the advantages and disadvantages of a POCO approach.

http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx

http://blogs.msdn.com/b/adonet/archive/2009/05/28/poco-in-the-entity-framework-part-2-complex-types-deferred-loading-and-explicit-loading.aspx

http://blogs.msdn.com/b/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx

In these articles the author mentions future articles that describe best practices in implementing Repository and Unit of Work patterns, but I can't find them. These articles are well written and I'd like to read more from this author.

Jinkinz
Thanks - They look useful :)
Basiclife
As someone already comfortable with Entity Framework using the designer, this was a great intro to POCO.
FerretallicA