© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
7 replies
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!;
}
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);
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ EF Core question
C#CC# / help
3y ago
EF Core
C#CC# / help
2y ago
Ef core help
C#CC# / help
10mo ago
✅ EF Core Relationship
C#CC# / help
2y ago