Model builder is throwing the following error:
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.Core.dll but was not handled in user code
Additional information: The derived type 'Namespace.myclass' cannot have keys other than those declared on the root type.
Context
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MyClass>((item) =>
{
item.HasKey(p => p.MyKey);
});
}
MyClass
public class MyClass
{
public MyClass()
{
OtherClass = new List<OtherClass>();
}
public int MyKey { get; set; }
public string Name { get; set; }
public virtual ICollection<OtherClass> OtherClass { get; set; }
}