Can I stop Entity Framework Core from populating my result with partial data?

前端 未结 1 414
有刺的猬
有刺的猬 2021-01-24 13:00

On this page of the Entity Framework Core documentation, it says when querying loaded data:

Entity Framework Core will automatically fix-up navigation pro

相关标签:
1条回答
  • 2021-01-24 13:32

    I assume from your example that Alice's message with id 1 is linked to more that one user (herself).

    I am not sure it is necessary to change this behavior. As you mentioned, we should use .ThenInclude(m => m.Users) if we need the navigation property to be fully initialized.

    I would expect that unless I also added .ThenInclude(m => m.Users), it would give me a null or empty list, not a partial list.

    The partial result will be a good thing when lazy loading will be implemented. If the navigation property you will want to access is already loaded, then you will save a round trip to the database.

    0 讨论(0)
提交回复
热议问题