我已经浏览了几个其他线程,这些线程引发了同样的错误,但没有得到解决方案:
public IQueryable GetHolidays(IQueryable<Location> locations, Location currentLocation)
{
int currentLocationType = currentLocation.FkLocationTypeId;
var holidays = ClientContext.Holidays;
//get all holidays for the given locations
var holidaysPerLocation = (
//get permissions added in their own level
from h in holidays
where (from l in locations where l.FkLocationTypeId >= currentLocationType select l.LocationId).Contains(h.FkLocationId)
&& h.FkHolidayParentId == null
select h)
.Union
(
//get permissions overriden at the current level
from h in holidays
where (from l in locations where l.FkLocationTypeId >= currentLocationType select l.LocationId).Contains(h.FkLocationId)
&& h.FkHolidayParentId != null && h.InheritedStatus == "U"
select h).Union
(
//get holidays from parent levels which are opted in
from h in holidays
join h1 in holidays on h.HolidayId equals h1.FkHolidayParentId
where (from l in locations where l.FkLocationTypeId < currentLocationType select l.LocationId).Contains(h.FkLocationId)
&& h.InheritedStatus == "I"
select h);
return holidaysPerLocation;
}
错误:“指定的LINQ表达式包含对与不同上下文关联的查询的引用。”
最初我试图直接在我的LINQ查询中查询ClientContext.Holidays,而不是单独将它带入内存,但这也给了我同样的错误。现在据我所知,我没有引用两个数据上下文,我不知道为什么会出现这个错误。