views:

129

answers:

5

Hi,

I've found various snippets on the web of how to use Code First in EF4 (from the futures CTP).

But I have yet to find a complete example of an object context, the context builder and a more advanced EntityConfiguration.

For example, in my entity configuration, how do I map a property on my domain object to a column with a different name e.g. Product.Id maps to "ProductId" column.

I've seen various snippets of code on building the context but am not sure where to put this code.

After learning NHibernate a few months ago I've never looked back but I would still like to see how good the POCO support is in EF - and by the looks of things (in the CTP) they are edging between a fluent style of mapping (like Fluent NHibernate)

+2  A: 

I think you will learn how to do it from this webcast It's a cast from NDC 2010 of Julie Lerman, I think the talk is called "Domain Focused Entity Framework".

Fossmo
any idea if you can download these videos rather than streaming?
Ben
A: 

The webcast @Fossmo posted helped a litte but the example application demo'd was just a console application where the context was build and accessed all within the same method.

What I was looking for is a more complete example demonstrating at what point to build the context and then how to access it from the other parts of your application (I expect something similar to the NHibernate session helpers people often used?).

In addition to this Julie Lerman continued to mention that the code first support will change significantly in CTP 4.

I found that Daniel Wertheim had some more complete examples (http://daniel.wertheim.se)

I think with Code First still being quite new to EF and it only being in the CTP that documentation is still quite sparse.

It is a shame really that EF4 was released and then they realised that code first is what a lot of developers have really been waiting for.

For now, I will stick to my NH xml mapping files - clean and simple.

Ben
A: 

Check out my post. It's very basic. You might learn something from it.

http://stackoverflow.com/questions/3128354/entity-framework-4-code-only-relationships

Jeroen
A: 

Here is a Tutorial.

It demonstrates how to use ASP.NET MVC 2, Entity Framework 4.0 CTP 4.0, Code First and custom convention mapping using EntityConfiguration class.

The fully working ASP.NET MVC 2 sample included in the article demonstrates how to map to existing databases with conventions different from the standard conventions, such as mapping to table names with prefix of 'tb', use of underscores '_' to separate words in column names and custom primary key naming conventions.

The link:** http://theminimalistdeveloper.com/2010/07/28/how-to-map-pocos-to-existing-databases-in-entity-framework-4-0-code-first-and-asp-net-mvc-2/**

Bikal Gurung
A: 

The Gu has an extensive blog entry about code first EF development here. It comes with a code sample download.

Igor Zevaka
Yes, have read this - definately the best post on the subject so far.
Ben