How is EntityFramework used in real life with C#?
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 solu开发者_JS百科tions in a real project?
Thanks alot for your time!
MS Certification exams and real life development have nothing in common. Those two are completely different worlds. So don't bother yourselves with crappy approach you have to use to complete labs in book (well you can make your own lab and spend much more time on correct approach if you want). That examples don't use layered architecture and they don't deal with separation of concerns.
Simply it is not done this way in the real world but explaining how it is done requires exact description of what type of application you want to do and what operation you want to execute.
Some info about the certification itself:
I took both DataAccess certification for .NET 3.5 and .NET 4.0. My experience was horrific. Especially DataAccess .NET 4.0 is probably the worst MS exam I have ever taken. I believe I understand EF little bit and I prepared myself by skimming through several chapters with topics I don't use very often in Programming Entity Framework, Entity Framework 4 Recipes, Entity Framework 4 in Action and Pro Linq (for Linq-to-Sql) + I read the whole ESQL reference. The training kit for this exam was not available during my preparation. It didn't help me at all. The exam questions about EF had very poor quality and I was lost most of the time because I felt that I needed more information to correctly select answer (with requirements provided more then one answer or none answer looked correct) or I needed to select more then one answer to fulfil all requirements in the question but I was allowed selecting only one.
Be aware that exam is not only about EF. In .NET 3.5 the exam contains almost none questions about EF. Half of questions in .NET 3.5 exam is about DataSets (OMG). In .NET 4.0 the exam contains half questions about EF, a lot of questions about plain old ADO.NET including few questions about data sets and few questions about remaining topics like Linq-to-sql, MS Sync Framework and data services.
I don't like to write it but .NET 4.0 exam convinced me that brain dumps can sometimes be handy because there is no appeal if you think that test was not correct or questions were not unambiguous.
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.
精彩评论