Аргументы конструктора, допускающие значение NULL, в иерархии универсальных классов C# ⇐ C#

Место общения программистов C#
Anonymous
Аргументы конструктора, допускающие значение NULL, в иерархии универсальных классов C#

Сообщение Anonymous »

Рассмотрим следующую общую иерархию классов сущностей EF Core:

Код: Выделить всё

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]

Вернуться в «C#»