我有以下操作方法:-
public ActionResult Index(string searchTerm=null, int page = 1)
{
var racks = repository.AllFindRacks(searchTerm).OrderBy(a=>a.Technology.Tag).ToPagedList(page, 5) ;
if (Request.IsAjaxRequest())
{
return PartialView("_RackTable", racks);
}
return View(racks);
}
以及以下存储库方法:-
public IQueryable<RackJoin> AllFindRacks(string q)
{
List<RackJoin> rakjoin = new List<RackJoin>();
var result = from rack in tms.TMSRacks
.Include(rack => rack.DataCenter)
.Include(rack => rack.Zone)
.Include(rack => rack.TMSFirewalls)
.Include(rack => rack.TMsRouters)
.Include(rack => rack.TMSServers)
.Include(rack => rack.TMSStorageDevices)
.Include(rack => rack.TMSSwitches)
.Include(rack => rack.Technology)
join resource in entities.Resources
.Include(a => a.ComponentDefinition)
.Include(a => a.ResourceLocation.SiteDefinition.SDOrganization)
.Include(a => a.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization)
on rack.Technology.IT360ID equals resource.RESOURCEID
where (q == null || rack.Technology.Tag.ToUpper().StartsWith(q.ToUpper()))
select new RackJoin {
Rack = rack,
Resource = resource,
Customer = resource.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization,
Site = resource.ResourceLocation.SiteDefinition.AccountDefinition.SDOrganization,
Technology = rack.Technology
};
return result;
}
但是当我调用 Action 方法时,我得到了以下异常:-
System.NotSupportedException 未被用户代码处理
HResult=-2146233067 Message=指定的 LINQ 表达式包含对与不同上下文关联的查询的引用。
源 = System.Data.Entity StackTrace: