Entity Framework 4.0 Beta 1 Sneak Peak Session at DotNetWork User Group in Cairo, Egypt

by mosessaur| 05 October 2009| 4 Comments

Introduction

Again I was honored to present a talk on first Egyptian .Net user group “DotNetWork”. My previous session -the first- was a joint session with Bishoy Ghaly about Entity Framework v1 in .Net 3.5 SP1. This session was about Entity Framework 4.0.

After we introduced Entity Framework to Egyptian community, I decided to give them a sneak peak at the new version of it. Comparing between both versions, showing the evolution and the massive enhancement made on the new version. The session covered the early CTP 1 of Entity Framework 4.0 Beta 1 that is released last June.

Presentation is available to download here.

Audiences

The main targeted audiences of this talk those who already had their hands on Entity Framework before. Those who experienced current version of Entity Framework on a way or another. And I would give my session level 200. So attending the first session in which we introduced Entity Framework was the least requirement for those who don’t know Entity Framework. Plus give it some hands on code to see what Entity Framework looks like.

The real audiences were totally something different. Few of them attended the first session. And I can sense that they didn’t really practice Entity Framework enough to know it well.

Part of the audiences were already didn’t know what’s ORM –probably students-! Some others where having their very first time to see what is Entity Framework and what it can do.

To be honest, to satisfy this kind of audiences is very hard! And I really hope that I was able to deliver as much as I can about what is Entity Framework, what it can do and comparing between current version and upcoming one.

Session Agenda

My agenda for the session was in the following sequence:

On the following I’m going to give a summary about my talk on each topic on the above agenda.

What’s new in Entity Framework 4.0 at glance

In this topic a comparison between current version of Entity Framework and vNext of Entity Framework was important. I talked about designer enhancements in general such as Pluralization & Singularization, support complex types and support for stored procedure mapping through the designer. I highlighted to the audiences how this was a problem in current version of Entity Framework and talked about where exactly the issues resides and how Entity Framework 4 Designer in VS.NET 2010 is going to solve these issues making development with Entity Framework more productive.

I also gave a hint about new APIs enhancements and additions which ease the development and testability of Entity Framework.

Other general overview and highlights about T4 templates and code generation customization, support of POCO, model first, code only etc…

This part of the session was just glance overview about some of the new stuff introduced in Entity Framework.

Designer Enhancements

Demos starts from here, people love to see things in action. So I demonstrated practically how Pluralization & Singularization works. And of course showed them how I am happy that I got this in EF4 as it wasn’t presented in current version.

Then the magic of refactoring to complex type! Sadly I was able to show them the magic, but couldn’t show them why this is magic by showing them practically that it will require us to modify the XML to add the complex type and do the mapping to get the job done on current version of Entity Framework.

Next demo was about mapping stored procedures to complex types! Another big improvement in Entity Framework.

Also showed them that updating model from database won’t erase manual modifications to entities! this is also was one of the limitation in current version which I highlighted.

There was another demo in this topic that I skipped for time. It was about Improvements in mapping insert,update & delete operations to stored procedure through Entity Framework designer. I just highlighted the difficulties in current version and told them that this is no more limitation and it is easy and straight forward to be done.

Deferred Loading Vs Explicit loading

One important topic raised since Entity Framework released. On of the demanded features was the support of deferred loading.

We didn’t go through eager loading, because it was one of the topics introduced on first session about EF, to save time I didn’t present it here.

I explained how explicit loading works in Entity Framework. Also introduced new explicit loading API in ObjectContext class which is LoadProperty method.

Then I explained what does deferred loading mean. And by examples and demos they recognized how this should work.

To this point I guess I spent 1 hour and 30 minutes. Between different demos and presentation slides.

Persistence Ignorance Support {POCO}

I started the session with a question! Does anybody know what is Persistence Ignorance mean! The general answer was NO. I already prepared myself to give a very short brief about Persistence Ignorance and the term POCO.

However I had a feeling that they didn’t recognize the benefit of being Persistence Ignorant and use POCO in designing entity models. And so I guess I might spent some time preparing a talk about this topic.

After defining PI and POCO I started to talk about Entity Framework support for POCO & PI. And that POCO entities has no dependencies on Entity Framework. I explored a bit about what is happening behind the scene and generation of proxies to support lazy loading and change tracking. Then I moved to the Requirements for Using Persistence-Ignorant Objects.

Finally the demo time, I demonstrated 3 things:

  • Working without lazy loading and change tracking.
  • Support lazy loading with not change tracking. Showing how entities can be modified to support that
  • Support lazy loading and change tracking. Showing how entities can be modified to support that.

By coincidence, I made few mistakes through the demos that violating few requirements of PI support. It was a good chance to show the audiences that following the requirements to support our requirements is important.

I also debug through the code to show the audiences the proxy created behind the scene to support change tracking or lazy loading.

Code Generation Customization Using T4 templates

This was a short topic, I used the T4 POCO template provided with CTP 1 for demonstration. I explored few benefits behind code generation customization such as applying validation rules or business rules etc..

Honestly I never wrote T4 template before. And it isn’t easy specially with the no intellisense support in T4 editor that is shipped out of the box with VS.NET 2010 Beta 1. So I just walked through how to use an existing T4 template –I used the POCO T4 Template-

Code Only support in Entity Framework 4.0

Moving to another new feature provided through CTP 1. Code Only Support. The name describes itself. I introduced the idea to the audiences! but again because most of the audiences were intermediate and beginner and maybe students they didn’t recognize the value of this feature.

Beside it is still in CTP, many things will be introduced later to enrich this feature more and more.

A demo to show this feature was important. Showing the extension APIs for creating a database from the model, mapping keys, creating/adding entities and finally commit changes to the database.

Self Tracking Entities in Entity Framework 4.0

An exciting new feature shown in the CTP 1. A Template that generate self tracking entities. First I explained what is self tracking entities, and showed to the audiences that self tracking entities are just pure POCO entities.

Moved back into history the days of DataSets where it was used to transfer data over a service to client application that does modifications on it and then pass it back to the service to commit updates in data stores. Talked about how bad this can be over the wire and disadvantages of doing this.

Then talked about the concept of DTOs, then moved to Self Tracking entities, which simply eliminates the need for doing manual change tracking, and eliminates the need for DTOs by using simple lightweight entities.

Self Tracking entities can be generated using provided T4 template in CTP 1. But also it can be manually coded. It is matter productivity I guess.

I walked through the generated code by the template to prove that the entities is totally pure POCO with no dependencies on Entity Framework infrastructure.

My demo was based on the walkthrough of Self tracking entities posted on ADO.NET team blog. Except that it was totally different scenario. I made a simpler demo for time saving.

I didn’t made the full walkthrough described in the post also for time limitation.

Conclusion

Generally I enjoyed the session and it really helped me in understanding more about Entity Framework in general and EF4 in specific. It made me admire the work done by the Entity Framework team, comparing to the current version. But a general note, audiences always ask! Why we didn’t have all this at first release! Or at least the things related to better designer experience and productivity?! Questions that personally couldn’t answer. But I consider EF v1 was a good start! and EF4 was enhanced because of community participation, comments and feedback provided about EF v1.

Now it is time to start to learn about Entity Framework basics. Master them and be ready for the new version. Entity Framework won’t stop on EF4 it will evolve and will become more powerful in future. Just be ready for it, NOW!

To download the presentation and demos click here. Demos are based on Northwind database, the script of the database is provided in the downloadable archive.

NOTE: References are provided inside the presentation on slides’ notes.

Comments

Emad Mokhtar
Emad Mokhtar Egypt on 9/28/2009 1:19 PM Hello Mr.Muhammad Mosa:
It's pleasure to attend this session with one productive and innovative geek, i learned from this session about EF but there's one tiny problem there, is that if anyone attend this session without attended that first one it will be too difficult to be online with you all the time.
So for me i was going online and offline sometimes, but i partially understand the session and it was perfect.

Best Regards,
Emad Mokhtar
Muhammad Mosa
Muhammad Mosa Egypt on 9/28/2009 11:39 PM I totally agree with you Emad. As I mentioned it will also require to have some hands on Entity Framework.
I was sure that many went offline at some points, I just hope it wasn't because of bad presentation Smile or because the presentation became boring Smile
Thank you for your comment. Wish to see you again in upcoming gatherings
Karim Ali
Karim Ali Saudi Arabia on 10/6/2009 6:35 PM Hello Smile ..
What a beautiful work ! Smile
But .. Any record to watch the previous or the next sessions? It 'll be nice to share it with us in the blog especially for who out side Egypt and can't attend ! Smile
Muhammad Mosa
Muhammad Mosa Egypt on 10/6/2009 11:55 PM Sorry Karim, we couldn't record the sessions! Although we tried to
Comments are closed