Exception when loading related objects. Entity Framework

前端 未结 1 1996
栀梦
栀梦 2021-01-17 10:20

I am getting an exception when loading related objects in my db. I am loading all my MatchData objects and I want to iterate them with a foreach.

The ob

相关标签:
1条回答
  • 2021-01-17 11:00

    The inner exception says it all:

    The class 'Boonekamp.ClassCollection.PlayerData' has no parameterless constructor

    Change your PlayerData to:

    [Obsolete("Only needed for serialization and materialization", true)]
    public PlayerData() {}
    
    public PlayerData(Player player)
    {
    }
    

    This way, you do have a parameter-less constructor that Entity Framework will be able to use during initialization. Yet, you prevent using that constructor in code using the [Obsolete] attribute.

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