【发布时间】:2019-08-30 01:49:32
【问题描述】:
我收到了这个错误
System.InvalidOperationException:实体类型“MyType”需要定义主键
尝试使用 DbContext、DbSet 等
我认为 MyType 不需要主键吗?
为什么我被告知要给它一个主键...
我创建了一些看起来像的模型
public ContainerType
{
public string Id { get; set; }
public int SomeData { get; set; }
public MyType Foo { get; set; }
public MyType Bar { get; set; }
}
public MyType
{
public string SomeProperty { get; set; }
public List<OtherType> OtherTypes { get; set; }
}
我尝试创建DbSet<ContainerType> Items,但每当我创建Items.Count() 时,我都会得到InvalidOperationException。
为什么?
【问题讨论】:
标签: c# asp.net asp.net-core .net-core