Entity Framework CodeFirst KeyNotFoundException in MemberDomainMap

前端 未结 3 1646
傲寒
傲寒 2021-01-06 16:55

Trying to run down an error in my EF datacontext implementation that is yielding a fairly cryptic error.

Test Name:  Nodes_can_be_saved
Test FullName:  MyP         


        
3条回答
  •  醉酒成梦
    2021-01-06 17:37

    I have the same issue, unfortunately none of the solutions here in StackOverflow worked for me aside from the answers on other questions related to this issue.

    But I found my own fix and you can also check it in your part if you have the same issue as mine. What happen is that if some class inherits from the table that I am using on my DbSet:

    public DbSet Employees { get; set; }
    

    On this case, if some other classes inherit from my POCO Employee, this triggers this particular error. I removed all inheritance from this class and this fixes the issue.

    Take note that this inheritance issue which triggers this same issue:

    The given key was not present in the dictionary.
    

    Only happens if the inheritance is on the same project. I tried to inherit the POCO on different project and it happens to be fine.

提交回复
热议问题