sudesh chhipa

sudesh chhipa

  • NA
  • 1
  • 3.5k

The specified LINQ expression contains references to queries

Dec 8 2014 8:20 AM
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.

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
 
var query = from rc in _FAQRepository.Table
join r in _FAQCategoryRepository.Table on rc.FAQCategoryID equals r.FAQCategoryID
select rc;
return query.ToList();
 
 
 
 
 

Answers (1)