Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm getting error after this join. Normal linq query working fine. I'm using database first approach.

When I'm collecting data from more than one table its throwing exception. The specified LINQ expression contains references to queries that are associated with different contexts.


C#
public partial class EfRepository<T> : IRepository<T> where T : class
{
    private readonly WebEntities _context;
    private IDbSet<T> _entities;

    public EfRepository(WebEntities context)
    {
        this._context = context;
    }

    public virtual IQueryable<T> Table
    {
        get
        {
            return this.Entities;
        }
    }

    protected virtual IDbSet<T> Entities
    {
        get
        {
            if (_entities == null)
                _entities = _context.Set<T>();
            return _entities;
        }
    }
}


Query on Service.cs

C#
var query = from rc in _FAQRepository.Table
            join r in _FAQCategoryRepository.Table on rc.FAQCategoryID equals r.FAQCategoryID
            select rc;
        return query.ToList();  
Posted

1 solution

SO Discussions[^]
Implement Repository and Unit of Work[^]
Look into the first link for your answer and the second one to get more idea on how to access two different context.
Post back queries if any.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900