What the purpose of OnModelCreating in EF4 Code-First? - entity-framework

I was curious about what the purpose of OnModelCreating in EF4 Code-First context class? How does it work?

Here is a nice article in ADO.NET Team Blog.
In short, this event is mainly for Fluent mapping.

OnModelCreating gives you access to a ModelBuilder instance that you can use to configure/customize the model.
As the previous answer mentions, you will typically use the code-first fluent API within it. Gil Fink has posted what IMHO is a clearer explanation than the article cited in the previous answer.
For background info, Guthrie has a nice intro article on EF Code-First, and if you are wondering why its referred to as "fluent API", look here.

Related

Conventions Roadmap for EF7

I'd like to get a clearer picture of the roadmap for Code First conventions for EF7. Presently there are three implementations of IEntityTypeConvention:
KeyConvention
PropertiesConvention
RelationshipDiscoveryConvention
Are there plans for achieving parity with EF6 CF conventions? For example, I don't see something like the PluralizingTableNameC convention. Also, what are plans for the API for customizing conventions?
As Anthony mentioned in his comment, this is currently on our backlog to be implemented - https://github.com/aspnet/EntityFramework/issues/214.
The API for custom conventions will likely look quite different from EF6 because of the new metadata API and our change to make ModelBuilder incrementally build a model rather than storing a bunch of configuration and then building the model when needed.

Purpose of Entity Framework DBContext Generator

This is probably an obvious question to many but I'm scratching my head over this one.
Can someone explain to me what purpose/advantage generating POCO classes via t4 templates such as the ADO.Net DBContext Generator has over standard EDMX data access?
I understand that they offer extensibility over the entity class definitions, but if a development team is not interested in that what other obvious purpose or advantages do they have?
Thanks
As mentioned by ThomasH in the comments the provided link gave me the info I needed.

Any Data Annotations tutorials that use EF Database-First approach to explain the subject?

All tutorials on Data Annotation attributes I've found explain the subject using either Asp.Net or EF Code-First examples. I don't know either of the two, so do you know of any tutorials that would explain the subject using EF Database-First approach?
Thank you
Here's one that's for ASP.NET Web Forms with EF Database First:
http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-8
This is the last installment in an 8-part tutorial series.

Fluent API, Annotations and EF 4.1

Would somebody please guide me towards links that explain Fluent API and Annotations when using EF 4.1 code first please? The more in depth, the better.
Thank you so much for your help in advance!
May issue of MSDN magazine contains article about EF 4.1. For further information check these blogs:
ADO.NET team blog
Morteza Manavi's Blog
Julie Lerman's Blog
You can also check this video but for that you need a subscription ($29 per month).
Almost everything can be found on Stack Overflow ;)
code-first ef-code-first entity-framework-4.1 dataannotations
http://msdn.microsoft.com/en-us/data/aa937723 has many tutorials on Entity Framework 4.1
Fluent API : http://msdn.microsoft.com/en-us/data/hh272551
Data Annotations : http://msdn.microsoft.com/en-us/data/gg193958

ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator (ObjectContext)

I am about to start implementing the data access infrastructure of a project that was architected with an approach to DDD (it's my first attempt on DDD, so be gentle ;-) ).
I will be using Entity Framework. Until now, I was looking into the method teached by Julie Lerman on her great book, Programming Entity Framework, where ADO.NET POCO Entity Generator is used, with some changes to the T4 templates and some more custom code.
Today I started reading articles on EF4.1 and the ADO.NET DbContext Generator, using Database First approach, and I'm trying to decide with which one should I go.
DbContext and EF4.1's approach on DDD seems to be a nice, cleaner way than POCO Entities, but I'm afraid that it could lead to some issues in the near future, since EF4.1 is still in RC.
From ADO.NET team blog, I know that EF4.1 does not include:
Enum support
Spatial data type support
Stored Procedure support in Code First
Migration support in Code First
Customizable conventions in Code First
From my understanding, since I will be using Database First there is a smaller number of features that were not included.
In conclusion, my question is:
Can I replace POCO Entities Generator with EF4.1 DbContext Generator?
From a point of view of clean creation of POCO entities, there is no difference between the two generators. Both generators produce the same entities, however, ADO.NET POCO Entity Generator is based on ObjectContext's API, whereas ADO.NET DbContext Generator is based on DbContext's API.
DbContext's API has a few very nice new features (Local, Query on navigation property, etc.) and API is somehow simplified but at the same time it looks like some features used in ObjectContext API are missing in DbContext API (or at least it has not been explored enough yet).
EF 4.1 RC is go-live release. It means that you can build a real application with it because API will not change in RTW (only bugs will be fixed). Also RTW should be in the next month so I think you will not be ready with your application before the final version is shipped.
ObjectContext API or DbContext API? ObjectContext API is much better covered by documentation and blog posts. You can find plenty of examples about it. Also its limitations are already well known. DbContext API is new release. A very promising release, mostly because of the code-first approach. There is still a very limited number of blog posts, no book and the API is not proven enough. So it depends if you are ready to fight with new API? If not, then ObjectContext API is still a good choice because you don't need the code-first approach.