1

I am implementing a college project to test the performance of the Entity Framework 4.0 compared to NHibernate (latest version). I am building a simple transaction processing system to do this testing. My entities will be things like Customer, Account, Order, Product.

I want to create two separate DALs; the first DAL will be the EntityFramework while the second will be NHibernate. I will then create a business logic layer (BLL) which references either one DAL or the other and use this to test. The BLL will include methods like 'insertNewOrder()', 'amendExistingOrder()' etc. I want my BLL to be framework independent so I can easily switch between each DAL.

To enable this, I propose to implement an Interface 'IContext' which will be implemented by each DAL. The 'IContext' will include my 'get()' methods for each entity and also a 'Save()' method. Each DAL will then implement these methods in their own specific way. The 'get()' methods will return an IObjectSet, rather than an ObjectSet.

I will use a T4 template to create POCO entities from my EDM and move these to a separate project. Each DAL can then reference the same set of POCO entities.

My BLL will then create an instance of the IContext interface and call methods on that interface, rather than creating a specific context (ObjectContext or ISession).

Does this sound like a feasible solution? Any article I find on this subject includes the use of repositories, a pattern which I don't fully understand and would like to avoid having to implement if possible. My focus is on testing each platform rather than building an application which is architecturally correct. See here for example:

Entity Framework POCO objects

I have partially based this approach on a chapter from "Programming Entity Framework 2nd Edition" by Julia Lerman. I am new to both NH and the EF (particularly NH), so any advice or recommendations would be appreciated. Thanks.

1

2 Answers 2

4

What you're looking for is the Repository Pattern. See (among many many other locations) https://stackoverflow.com/questions/3175/repository-pattern-tutorial-in-c as an example.

The idea behind the repository pattern is that you create interfaces for your data access, e.g.:

public interface IAddressRepository { Address GetById(int id); } 

Then you create two implementations of this interface: one for the Entity Framework and one for NHibernate.

Last, you create a mechanism to get the implementation you require based on the interface. IoC containers like Windsor are great at this.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want to test performance, you shouldnt create middle layer. Go with raw code in both cases that have same input/output, but nothing more.

Creating a middle layer will limit you to smallest denominator for both cases. By implementing both competing parts separatedly, you can do optimalizations and concrete implementations specific to one technology that would be impossible to do with same access layer.

Also your assignment is not to create same DAL, but to test performance. So you should first start worrying about optimalizations and special cases in both technologies before trying something else.

1 Comment

Thanks for the reply. I think that I'll continue with my middle layer approach for now though. I'm happy to keep the scope of the project limited to how the frameworks perform in a (relatively) default configuration when applied to a specific scenario (a transaction processing system in this instance). I've been advised by a supervisor to ensure I compare like with like, and also these are fairly substantial frameworks. If I look at each separately I may end up with way too much material and never finish!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.