Entity Framework has changed drastically since they have introduced version 1. EF 4.1 has improved Code First and Fluent mappings which are really impressive. However, I have a worry about complex query implementations on EF 4.1 because it depends on DbContext strongly. Entity SQL and Linq to Entities keep on changing it’s behavior with SQL queries. I feel we need a strong Query mechanism like HQL or Criteria to overcome this. What you think ?
Entity Framework has changed drastically since they have introduced version 1. EF 4.1 has
Share
Many modern .NET ORMs provide an IQueryProvider implementation (including NHibernate). I choose to remove the direct dependency on EF by using POCO T4 template, then modifying it to generate an interface (IMyRepository) that returns plain IQueryables instead of ObjectSets. The underlying implementation of IMyRepository using a ObjectContext. If we decide to move away from EntityFramework, we can just change the implementation of IMyRepository to use someone else’s LINQ IQueryProvider.
Further, this allows us to work in a distributed scenario. For example, one implementation of IMyRepository lives on the client and uses DataServiceClient (WCF Data Services) to call out to the server, which has a different implementation of IMyRepository, which uses Entity Framework directly.
In the case of Code First, this is also fairly easy to do. Your classes are already POCOs…so just make your DbContext implement an interface that returns IQueryables instead of DbSets.
I personally then inject the IMyRepository using dependency injection.