AbrahamJLR
AbrahamJLR
CC#
Created by AbrahamJLR on 3/17/2023 in #help
❔ Jetbrains Rider Config
2 replies
CC#
Created by AbrahamJLR on 1/14/2023 in #help
❔ 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?
22 replies