Using .Net 4.8 I have all my entity framework classes inheriting from an AbstractBase:
public abstract class AbstractBase
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int Id { get; set; }
public virtual DateTime CreatedTimestamp { get; set; }
public virtual DateTime UpdatedTimestamp { get; set; }
[Required]
public virtual int CreatedBy { get; set; }
[Required]
public virtual int LastModifiedBy { get; set; }
public virtual bool ActiveFlag { get; set; }
[JsonIgnore]
public virtual User CreatedByUser { get; set; }
[JsonIgnore]
public virtual User LastModifiedByUser { get; set; }
public string ToActiveInactive()
{
return this.ActiveFlag ? "Active" : "Inactive";
}
}
Now as you can see I am ignoring the CreatedByUser
and LastModifiedByUser
.
What I would like to do instead is somehow replace the User object
with a property called FullName
which the User object can provide like
User test = new User();
test.GetFullName();
My User object already has this so my question is there a way to do this so I do not have to write more implementation of the same logic every time I want to serialize an entity class?