In a previous post regarding the ISession from Rob Conery, a commenter asked about our implementation of ISession with regards to EF4. Rather than send him the specific code, I figured I’d make another blog post to outline exactly how we use it here at work.
Basically, each of our projects has a “Data” layer where we store everything needed to communicate with the database. This is also where the ISession interface lives, so it’s easy to provide the implementation. There is one caveat, however, because we need to provide a generic EF4 implementation that can work with any data context. In our projects, sometimes we need to speak with multiple databases, and then it becomes just a matter of plugging the right entity collection into our implementation. Here’s what the code looks like: