EF Code First Lazy loading Not Working

后端 未结 2 1192
别跟我提以往
别跟我提以往 2021-02-05 04:06

I am using code first with EF6 but cannot seem to get lazy loading to work. Eager loading is working fine. I have the following classes:

public class Merchant :          


        
相关标签:
2条回答
  • 2021-02-05 04:25

    I realized that the problem was that the Merchant class did not meet requirements for proxy generation. Specifically, I needed to add a protected parameterless constructor. I only had a private one.

    0 讨论(0)
  • 2021-02-05 04:36

    Another thing that can cause lazy loading to fail is navigation properties that are not virtual. That was not the case for OP, but this question is a top Google result so it may help some.

    And yet another possible cause is a mapped database column that doesn't exist. I was surprised to see that break lazy loading rather than throw a database exception.

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