开发者

Enhance this LINQ query for readability and performance?

开发者 https://www.devze.com 2023-01-08 05:17 出处:网络
I\'m not the greatest with LINQ, but I\'m trying to retrieve all the ModuleAvailabilities where the academicYear is the current year.

I'm not the greatest with LINQ, but I'm trying to retrieve all the ModuleAvailabilities where the academicYear is the current year.

Are there any improvements to be made here?

pathway.PathwayFoundationModule.Attach(
    pathway.PathwayFoundationModule.CreateSourceQuery()
        .Include("Module")
        .Include("Module.ModuleAvailabilities.Location")
        .Where(o => o.Module.ModuleAvailabilities
                     .Where(x => x.AcademicYear == academicYear.Current)
     开发者_开发问答                .Count() >= 0)
);


I think you mean

pathway.PathwayFoundationModule.Attach(
            pathway.PathwayFoundationModule.CreateSourceQuery()
                .Include("Module")
                .Include("Module.ModuleAvailabilities.Location")
                .Where(o => o.Module.ModuleAvailabilities
                    .Any(x => x.AcademicYear == academicYear.Current));
0

精彩评论

暂无评论...
验证码 换一张
取 消