© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
21 replies
AbrahamJLR

❔ Entity Framework relationship problem between entities.

Hello, I am currently doing an Entity Framework internship and I have a relationship problem between entities.

In the beginning we are given a base class "Entity", which has certain properties, its diagram is clear and simple. I associate the original class:

public abstract class Entity
{
     [Key]
     public Int64 Id { get; set; }
     public Boolean IsDeleted { get; set; } = false;

     public String CreatedByUser { get; set; } = string.Empty;
     public String EditedByUser { get; set; } = string.Empty;
     public String DeletedByUser { get; set; } = string.Empty;
    
     public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
     public DateTime EditedAt { get; set; } = DateTime.UtcNow;
     public DateTime DeleteAt { get; set; } = DateTime.UtcNow;
}
public abstract class Entity
{
     [Key]
     public Int64 Id { get; set; }
     public Boolean IsDeleted { get; set; } = false;

     public String CreatedByUser { get; set; } = string.Empty;
     public String EditedByUser { get; set; } = string.Empty;
     public String DeletedByUser { get; set; } = string.Empty;
    
     public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
     public DateTime EditedAt { get; set; } = DateTime.UtcNow;
     public DateTime DeleteAt { get; set; } = DateTime.UtcNow;
}


This class is inherited by the "User" class. Code:
public class User : Entity
{
     [Required, StringLength(50)]
     public String Name { get; set; } = string.Empty;

     [Required, StringLength(100)]
     public String LastName { get; set; } = string.Empty;

     [Required, EmailAddress]
     public String EmailAddress { get; set; } = string.Empty;

     [Required]
     public String Password { get; set; } = string.Empty;
}
public class User : Entity
{
     [Required, StringLength(50)]
     public String Name { get; set; } = string.Empty;

     [Required, StringLength(100)]
     public String LastName { get; set; } = string.Empty;

     [Required, EmailAddress]
     public String EmailAddress { get; set; } = string.Empty;

     [Required]
     public String Password { get; set; } = string.Empty;
}


My problem is the following assignment: "Create the necessary relationships between "User" and "Entity", where instead of using "String" for the properties (CreatedByUser, EditedByUser, DeletedByUser) use an instance of the "User" class.

I've been having trouble posing this assignment correctly mainly because of the inheritance present between User and Entity. What would be the correct way to approach this relationship?
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

relationship navigations entity framework
C#CC# / help
13mo ago
❔ Entity framework migration problem
C#CC# / help
3y ago
Entity framework
C#CC# / help
14mo ago
❔ Entity Framework
C#CC# / help
3y ago