增强此LINQ查询的可读性和性能?

时间:2010-07-22 16:32:14

标签: linq linq-to-entities linq-to-objects

我不是LINQ的最佳人选,但我正在尝试检索ModuleAvailabilities当前年份的所有academicYear

这里有什么改进吗?

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)
);

1 个答案:

答案 0 :(得分:5)

我认为你的意思是

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