consider following code:
if (storeId > 0)
{
query = from t in query
join sm in _storeMappingRepository.Table on t.Id equals sm.EntityId into t_sm
from sm in t_sm.DefaultIfEmpty()
where !t.LimitedToStores || (sm.EntityName == "Plugin_Tables" && storeId == sm.StoreId)
select t;
//only distinct items (group by ID)
query = from t in query
group t by t.Id
into tGroup
orderby tGroup.Key
select tGroup.FirstOrDefault();
query = query.OrderBy(t => t.Id);
}
the exception will be thrown in the "query.OrderBy" method, you will see this error:
"The specified LINQ expression contains references to queries that are associated with different contexts"
any idea?