Can you exclude reverse navigation properties in EF when eager loading?

前端 未结 2 1570
醉话见心
醉话见心 2021-01-19 02:09

When I use the .Include syntax in EF6, reverse navigation properties are always loaded. Is there a way to turn that off? Here is a sample query.

private stat         


        
2条回答
  •  青春惊慌失措
    2021-01-19 02:09

    I think what you're seeing is a result of "relationship fix-up":

    Relationship fix-up ensures that related objects are automatically linked when the second entity enters the ObjectContext.

    http://blogs.msdn.com/b/alexj/archive/2009/10/13/tip-37-how-to-do-a-conditional-include.aspx


    In your case, since you're including AccountLocation.Address.City, EF is loading the related Address entities and the related City entites that you requested, and as part of the "fix-up" it's adding the loaded Address entities that would be part of the City->Address one-to-many relationship to the City.Addresses navigation collection.

    You can find another example at this link. As in your case, lazy loading and proxy creation were also disabled -- however, that link doesn't include a way to disable this behavior.

提交回复
热议问题