I just finished a Guerrilla.NET in Boston with Michael Kennedy and Mark Smith. Here are the topics we covered.

  • Introduction to WPF and Silverlight
  • ASP.NET MVC 3.0: Beyond the Basics
  • LINQ to Objects and LINQ to XML
  • Entity Framework
  • Model-View-ViewModel for WPF and Silverlight
  • PFx: Task and The Parallel Class
  • Thread Safety and Concurrent Data Structures
  • Building WCF REST Services
  • C# 3.0, 4.0, and 5.0
  • Entity Framework and the Repository Pattern
  • jQuery
  • Cloud Computing for the .NET Developer: IaaS, PaaS, and Patterns
  • The NoSQL Movement, LINQ, and MongoDB
  • iOS Programming with .NET and MonoTouch
  • Design Patterns for Testability (DI, IoC, and unit testing)
  • Reactive Framework for .NET (Rx)
  • WCF Data Services
  • Power Debugging with WinDBG

I had a great time, and as an added bonus I learned some things. I was monkeying for Mark while he was doing the “Entity Framework and the Repository Pattern”. He did two things that I thought were better than I had done in the past. But first some background…

I used to structure my repositories using an interface similar to this:

IEnumerable<T> GetAll() // or sometimes returning an IList
T GetById(TKey id)  // sometimes just taking an object
void Add(T t)
void Delete(TKey id) // sometimes taking a T
void Save()

I may have other interfaces which specialize a particular IRepository to contain additional query methods.
Sometimes when I am implementing the repository pattern I combine it with a session object. This is especially nice when using NHibernate or doing Web work (where the controller method creates the session and closes it before returning). The session will hang on to the context so that different repositories can be called together in a transaction.

Mark pointed out two things that work differently in Entity Framework and LINQ than in other ORMs.
1) Save() doesn’t need to go on the individual repositories anymore it can be moved up into the Session object. This is because SaveChanges() commits all changes across anything using the same context.
2) If you change the All method to return an IQueryable you can remove all of the other Get methods, because they can be built using LINQ.

So the new IRepository looks like:

IQueryable<T> All
void Add(T t)
void Delete(T t)

That is a good simplification, thanks Mark.

No comments yet.

No Comments

Sorry, the comment form is closed at this time.