我有一个场景,我试图为特定目的创建一个相同类型的嵌套集合的可增长层次结构,并且我正在使用EF Core 2.2。
public class Group:Entity
{
public Group(Guid id):base(id)
{
}
...
public List<Group> SubGroups { get; set; }
}
public abstract class Entity
{
protected Entity(Guid id)
{
Id = id;
}
public Guid Id { get; private set; }
}
目标是保存如下数据:
|-GrandParent Group
-Parent Group
|--Child1 Group
---GrandChild1 Group
|--Child2 Group
---GrandChild2 Group
错误
{System.InvalidOperationException: No suitable constructor found for entity type 'Group'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'guid' in 'Group(Guid guid)'.
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConstructorBindingConvention.Apply(InternalModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelBuilt(InternalModelBuilder modelBuilder)
你能告诉我我怎么能做到这一点吗?