© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
2 replies
joren

Using base class as relationship definition in model ASP.net WEB API

So I've written this model that I used to save my credentials to authenticate my users with:

public class UserCredentialsModel : IdentityUser, IModelEntity
{
    [Required]
    string Id { get; set; }

    [Required]
    public DateTime CreatedAt { get; set; }

    public ICollection<RefreshTokenModel> RefreshTokens { get; } = new List<RefreshTokenModel>();

    // Does this work?
    public BaseProfile profile { get; set; }
}
public class UserCredentialsModel : IdentityUser, IModelEntity
{
    [Required]
    string Id { get; set; }

    [Required]
    public DateTime CreatedAt { get; set; }

    public ICollection<RefreshTokenModel> RefreshTokens { get; } = new List<RefreshTokenModel>();

    // Does this work?
    public BaseProfile profile { get; set; }
}


Now as you can see I have a
BaseProfile
BaseProfile
here, each credential has its connected profile attached. It is a one to one relationship. However, I have multiple types of profiles, that have a few things in common so I wrote a base class like this:
   public class BaseProfile : IModelEntity
   {
       public string Id { get; set; }


       [Required]
       public string FirstName { get; set; }

       [Required]
       public string LastName { get; set; }

       public UserCredentialsModel UserCredentials { get; set; }
   }
   public class BaseProfile : IModelEntity
   {
       public string Id { get; set; }


       [Required]
       public string FirstName { get; set; }

       [Required]
       public string LastName { get; set; }

       public UserCredentialsModel UserCredentials { get; set; }
   }


and then I have different profiles that inherit from this, would this relationship still work as intended when using
Baseprofile
Baseprofile
? Or do I need to have a field for each profile and have them as nullable/have some enum to decide the profile type and use that as a way to differentiate
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

✅ ASP.NET Core Web API Model Creation.
C#CC# / help
10mo ago
ASP.NET Web API base API route / route prefix?
C#CC# / help
3y ago
✅ Authorization in ASP.NET Web Api
C#CC# / help
2y ago
✅ ASP.Net Core Web API
C#CC# / help
6mo ago