I have implemented Generic repository which only depends on IUnitOfWork (in Infrastructure.Repositories Library) and also haven’t used any references to Entity Framework 4.1 dll. Entity Framework’s DbContext wrapped with EFUnitOfWork which is in different class library called Infrastructure.EntityFramework. However, I came across some difficulty with Linq to Entity query that may force me to include direct dependancy with repository and EF 4.1 library.
In one of my class repository I need to use following query with a join. How can I overcome DBContext usage in my repository ?
var result = from cc in ProjectXEFDbContext.CurrentContext().PurchaseOrderLineItemCollection
join bb in GetQuery() on cc.PurchaseOrderId equals bb.Id
where bb.Id == purchaseOrder.Id && cc.Total > 50
select cc;
I made my repositories to expose IQuerables over DbContext. DbContext wrap with UnitOfWork as follows
My Repository base goes like this
my unit of work implementation goes here
Changes to my query as follows