我正在尝试构建我的代码并能够更好地维护我的一些 LINQ 查询。IQueryable
实际上,我创建了一个带有一些函数的新助手类,但是在另一个函数中执行我的一些函数时遇到了一些问题IQueryable
。
当我执行该函数时SupplierMappings.GetSupplierAssociatedRT(int supplierID)
,我收到以下错误:
方法 'System.Linq.IQueryable`1[VMPortal.DataAccessLayer.CostCentre]
GetSupplierAssociatedCCPerRT(Int32, Int32)' 不支持 SQL 转换。
我做错了什么?以下是相关代码的一部分:
public class SupplierMappings
{
private static DataLayer dl = DataLayer.GetDataContext();
public static IQueryable<ResourceType> GetSupplierAvailableRT(int supplierID)
{
return dl.ResourceTypes.Where(x =>
dl.SuppliersCompanies2.Any(y => y.SupplierID == supplierID
&& y.ResourceTypeID == x.ResourceTypeID
&& y.StatusID == (short)SuppliersCompaniesStatusEnum.Active));
}
public static IQueryable<ResourceType> GetSupplierAssociatedRT(int supplierID)
{
return GetSupplierAvailableRT(supplierID).Where(x =>
// Check if we have at least one CC associated with that RT
GetSupplierAssociatedCCPerRT(supplierID, x.ResourceTypeID).Count() >= 1);
}
public static IQueryable<CostCentre> GetSupplierAvailableCCPerRT(int supplierID, int rtID)
{
return dl.CostCentres.Where(x => x.StatusID == (short)CostCentersStatusEnum.Active
// Check than the supplier is mapped at supplier level at same company & RT
&& dl.SuppliersCompanies2.Any(y => y.CompanyID == x.CompanyID
&& y.SupplierID == supplierID
&& y.ResourceTypeID == rtID
&& y.StatusID == (short)SuppliersCompaniesStatusEnum.Active)
// Check than the PA is active
&& x.DeliveryGroup.StatusID == (short)DeliveryGroupsStatusEnum.Active);
}
public static IQueryable<CostCentre> GetSupplierAssociatedCCPerRT(int supplierID, int rtID)
{
return GetSupplierAvailableCCPerRT(supplierID, rtID).Where(x =>
dl.SuppliersCostCentre2.Count(y => y.SupplierID == supplierID
&& y.StatusID == (short)SuppliersCostCentreStatusEnum.Inactive
&& y.ResourceTypeID == rtID) != dl.SuppliersCompanies2.Count(y => y.SupplierID == supplierID
&& x.CompanyID == y.CompanyID
&& y.StatusID == (short)SuppliersCompaniesStatusEnum.Active
&& y.ResourceTypeID == rtID)
&& dl.SuppliersPracticeAreas.Count(y => y.SupplierID == supplierID
&& y.StatusID == (short)SuppliersPracticeAreaStatusEnum.Inactive
&& y.ResourceTypeID == rtID) != dl.SuppliersCompanies2.Count(y => y.SupplierID == supplierID
&& x.CompanyID == y.CompanyID
&& y.StatusID == (short)SuppliersCompaniesStatusEnum.Active
&& y.ResourceTypeID == rtID));
}
}