0

Given the class

public abstract class Entity<T> : IEntity<T>, IAuditableEntity,ISoftDeletable where T : struct, IComparable
{
    public virtual T Id { get; set; }
    public virtual DateTime CreatedDate { get; set; }
    public virtual string CreatedBy { get; set; }
    public virtual DateTime UpdatedDate { get; set; }
    public virtual string UpdatedBy { get; set; }
    public virtual bool Deleted { get; set; }
}

from which several types are derived, how one can, using automapper transform them into something whose base class would look like

public abstract class ViewModelEntity<T> : Entity<T>, where T : struct, IComparable
{
    public virtual T Id { get; protected set; }
    public virtual DateTime CreatedDate { get; protected set; }
    public virtual string CreatedBy { get; protected set; }
    public virtual DateTime UpdatedDate { get; protected set; }
    public virtual string UpdatedBy { get; protected set; }
    public virtual bool Deleted { get; protected set; }
}

meaning, i want my viewmodels to disallow the setters for those base properties, but not any other property the entity might have.

The relevance of this is that those properties will be automatically set at the data layer/repository level and the UI coder can only consume them

sergio
  • 1,026
  • 2
  • 19
  • 43
  • create a constructor that takes and sets those properties, then use automapper with `ConstructUsing` and allow it to map the rest. [See this question](http://stackoverflow.com/questions/2239143/automapper-how-to-map-to-constructor-parameters-instead-of-property-setters) – Jonesopolis Nov 02 '15 at 17:18
  • Im not sure that fits my use case. the id for example, its an identity column and i dont know it when i want to create a new object. – sergio Nov 02 '15 at 17:20
  • Why does `ViewModelEntity` inherit from `Entity`? Do you realize that the properties in `ViewModelEntity` are hiding the properties from `Entity`? – Yacoub Massad Nov 02 '15 at 20:47
  • What did you try to do? and what issue did you face? – Yacoub Massad Nov 02 '15 at 20:56

0 Answers0