3.1.11.0706 Final (SD.LLBLGen.Pro.DQE.SqlServer.NET20.dll)
3.1.12.0806 (SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll
3.1.12.0507 (SD.LLBLGen.Pro.LinqSupportClasses.NET35)
DotNet 4.0 vs2010 project
Adapter template
I have an entity collection with prefetch path that defined lots of criteria. I want to project it into custom classes that contain counts. When I do this without getting the collection as an IEnumerable or List then the counts ignore all the criteria. If I first do ToList() the counts then work.
Here is the (simplified) code the get the count(s):
var facilityRegionEntities = model.RegulationCountryRegions<FacilityEntity>(438, "cm");
var countryRegions = from a in facilityRegionEntities.ToList()
select new Dashboard
{
FacilityCode = a.FacilityCode,
CountryCode = a.CountryCode,
RegionCode = a.RegionCode,
TotalRegulations =
a.RegionBase.RegulationCountryRegionIncludeFederal.Distinct().Count(),
};
and here is the (simplified) Linq for the criteria:
public IQueryable<FacilityEntity> RegulationCountryRegions<T>(int idClient, string serviceCode)
{
var facilityRegionEntities = (from regions in metaData.Facility
where regions.IDClient == idClient
&& regions.ServiceCode.Equals(serviceCode, StringComparison.CurrentCultureIgnoreCase)
select regions)
.WithPath(regions => regions.Prefetch<RegionBaseEntity>(y => y.RegionBase)
.FilterOn(y3 => y3.ClientRegion.Any( b => b.IDClient == idClient && b.ServiceCode.Equals(serviceCode, StringComparison.CurrentCultureIgnoreCase)))
.SubPath(y1=>y1.Prefetch<RegulationCountryRegionIncludeFederalEntity>(y2=>y2.RegulationCountryRegionIncludeFederal)
.FilterOn(y2=>y2.RegulationBase.Archived == false))
);
return facilityRegionEntities;
}
If I remove the .ToList() then the criteria is ignored but the performance is terrible (timesout after 30 seconds)
How do I construct a collection so that counts are carried out on the database? I can manually modify the generated sql to add counts, but I don't quite manage to create the Linq to do it itself.