項目中用EF實現外鍵查詢出的數據, 查詢數量正確, 但實現返回數據集數量不對ui
//DbContext.cs HasRequired(s => s.ClassRoom) .WithMany() .HasForeignKey(student => student.ClassRoomId);
//查詢語句 dbRead.Set<Student>().Include(x=>x.ClassRoom);
查詢 .Count()和.ToList()結果數量不一致spa
經調試後發現生成的Sql語句爲 inner join調試
正確的結果應該是 left joincode
此時應該以下定義外鍵blog
HasOptional(s => s.ClassRoom) .WithMany() .HasForeignKey(student => student.ClassRoomId);
此時返回的結果就正確了!it