I am currently intresting on learning myself using Entity Framework since I like the basic idea with OR mapping.
However to learn this my intention was to take a certification in Entity Framework (DataAccess the certification is called in Microsoft world).
After have started to read the exam book and also doing the labs I have come to the conclusion that many things gets pretty hard tightned in the UI with the Entity Framework (at least in the book). I refuse to think that this is the way it’s done in the real life projects.
So I have two questions (maybe they map together a bit):
-
How do I realy handling the ObjectContext in real life? Is it realy open all the time as in the labs? They passing it around to different windows and keeping it open. This feels for me at least pretty stupid at least in the way of re use of my code. Since in the end there will be X amount of database questions that is exactly the same in a bigger project.
-
Do anyone have a good link to a pattern that you have used for your Entity Framework solutions in a real project?
Thanks alot for your time!
You are correct that the labs do suggest working like that is just fine. I suggest you take a look at Entity Framework 4 in action.
Most of the time you’ll put your entity framework context behind an interface to reduce coupling and improve testability. With EF4 (and even better in 4.1) we also now have POCO support which means your entities don’t have to inherit from any special Entity Framework class.