ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator (ObjectContext)
Asked Answered
D

1

58

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?

Deemphasize answered 17/3, 2011 at 15:10 Comment(1)
[very tangentially] related (Linq to Sql): #3471955Barnhill
L
54

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.

Leboeuf answered 17/3, 2011 at 15:28 Comment(9)
What did you mean by "local" (in the list of new features)?Surcharge
@Danny: DbSet has Local property which allows you easily querying already loaded entities without new query to database.Leboeuf
Thanks, I was disappointed to see it didn't make it to VS2010SP1.Surcharge
@Ladislav, 1. Is there a DbContext generator (e.g. DB first with edmx designer & generator)? where can I find it and start using it? 2. Is it supported by RIA Services (e.g. like `LinqToEntitiesDomainContext<TContext>'?Hedger
@Shimmy: When you install EFv4.1 you will have new T4 template available - DbContext Generator. It will create DbContext from EDMX file. I don't know anything about RIA services so I can't answer you second question.Leboeuf
Thanks. I installed it and it's great, but unfortunately I can't use because it doesn't qualify for question 2. please vote: dotnet.uservoice.com/forums/57026-wcf-ria-services/suggestions/…Hedger
@LadislavMrnka - in both cases then there are proxies created behind the scenes?Cattima
For the sake of have an up to date answer, perhaps add the same link as this answer on how to reach ObjectContext's API vs DbContext's API: thedatafarm.com/blog/data-access/…Surcharge
@LadislavMrnka Can you please check this question #13535503Caudate

© 2022 - 2024 — McMap. All rights reserved.