public abstract class Parent
where TUserKey : IEquatable // same signature as IdentityUser
{
protected Parent() { } // non-public ctor for use by EF
protected Parent(TUserKey? userId) { UserId = userId; }
public long Id { get; }
public TUserKey? UserId { get; } // nullable because optional relationship
// other properties...
}
public sealed class Child : Parent
{
private Child() : base() { } // non-public ctor for use by EF
public Child(long? userId) : base(userId) { } //
Подробнее здесь: [url]https://stackoverflow.com/questions/79166724/nullable-constructor-arguments-in-c-sharp-generic-class-hierarchy[/url]
Рассмотрим следующую общую иерархию классов сущностей EF Core: [code]public abstract class Parent where TUserKey : IEquatable // same signature as IdentityUser { protected Parent() { } // non-public ctor for use by EF