C#C
C#3y ago
barcode

❔ EF Core question

public class User : BaseEntity
{
    public ulong OAuthId { get; set; }
    public Role Role { get; set; }
    public ICollection<UserClient> UserClients { get; set; } = null!;
    public ICollection<Client> Clients { get; set; } = null!;
}


Currently I define my models like this, should these collections be defined as null! or should I do new List<Client>() in the class?

var clients = _clients.GetClients()
                    .Where(x => createUserDto.ClientIds!.Contains(x.Id));
       // TODO: add clients
       user.Clients = new List<Client>();
       clients.ToList().ForEach(x=> user.Clients.Add(x));
                
      await _users.CreateUser(user);


currently I add clients when I create an user like this
Was this page helpful?