我首先使用数据库中的代码,这里是类:
[Table("Language")]
public partial class Language
{
public Language()
{
LocaleString = new HashSet<LocaleString>();
}
public int Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
[Required]
[StringLength(20)]
public string Culture { get; set; }
public virtual ICollection<LocaleString> LocaleStrings { get; set; }
}
[Table("LocaleStringResource")]
public partial class LocaleString
{
public int Id { get; set; }
public int LanguageId { get; set; }
[Required]
[StringLength(200)]
public string Name { get; set; }
[Required]
public string Value { get; set; }
public virtual Language Language { get; set; }
}
当我说localeString存储库时:repository.GetIQueryable()
结果是:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[LanguageId] AS [LanguageId],
[Extent1].[Name] AS [Name],
[Extent1].[Value] AS [Value]
FROM [dbo].[LocaleStrings] AS [Extent1]}
为什么我说repository.GetIQueryable()。ToList()结果列表包括Language属性,类型类似于dynamicProxies.Language,这意味着ToList也加载关系数据或只是因为看到结果在调试器?感谢
答案 0 :(得分:0)
如果查询是您已粘贴的,则EF在调试器中延迟加载语言属性。您实际上可以检查它:如果您没有快速连接,当您将鼠标悬停在该属性上时可能会有轻微的延迟/延迟。是这样的吗?如果是,那么当您悬停时,EF会延迟加载该属性。您可以通过关闭延迟加载并尝试相同来100%确定。如果加载失败,那就是延迟加载。