简体   繁体   English

实体框架-删除项目列表

[英]Entity Framework - Remove List of Items

I am trying to delete a list of items from a database with entity framework, however I can't get the sub lists not to load, 我正在尝试从具有实体框架的数据库中删除项目列表,但是无法获取不加载的子列表,

essentially I have a list for which each item of that list contains a 2 list, I want to not load the sub lists but just the list it self. 本质上,我有一个列表,该列表的每个项目都包含一个2列表,我不想加载子列表,而只是加载自身的列表。

How do I only load the list and not its sub lists? 如何仅加载列表而不加载其子列表?

It's possible that the sub lists are being LazyLoaded when they are evaluated. 评估子列表时,它们可能会被LazyLoaded加载。 You can turn Lazy Loading off with 您可以通过以下方式关闭“延迟加载”

DbContext.Configuration.LazyLoadingEnabled = false; 

More details here . 更多细节在这里 I typically turn LazyLoading off in the constructor of my context and eager load anything I need with include statements. 我通常在上下文的构造函数中关闭LazyLoading,并渴望通过include语句加载我需要的任何内容。 Lazy Loading can also cause performance issues. 延迟加载也会导致性能问题。 If you loop through a lazy loading collection you'll end up with one database hit per item in the collection. 如果循环浏览一个懒惰的加载集合,则最终会导致该集合中每个项目命中一个数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM