How do you do a join on two tables when you are implementing uows & a generic repository

asp.net-mvc entity-framework entity-framework-6 linq

Question

My unit of work is basically set up as this tutorial, with minor additions:

http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

I want to know how to do a join on two tables. I tried adding this to GenericRepository, but as you may guess my Linq knowledge is dubious.

public virtual IQueryable AsQueryable()
        {
            IQueryable<TEntity> query = dbSet;
            return query;
        }

And then doing

// uow is defined as new UnitOfWork() on class instantiation
var data = from x in uow.MyRepository.AsQueryable() 
           join y in uow.MyOtherRepository.AsQueryable() 
           on x.prop1 equals y.prop2

But it wont let me access properties within my table. I basically need a way of returning the table as a queriable entity (I think)

1
0
2/22/2015 4:03:46 PM

Popular Answer

Ironically I worked it out straight after posting. Result, for those who find the same issue:

var entity1 = uow.repo1.Get();
var entity2 = uow.repo2.Get();
var res = (from x in entity1 
          join y in entity2 
          on x.propToJoin equals y.propToJoin 
          select new 
          {
              test = x.propertyToGrab
          }).ToList();
0
2/22/2015 4:11:31 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow