0

So I'm currently debating the option of either defining concrete classes with properties, or to go with a metadata-type design. For example:

public class Employee
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string EmployeeCode { get; set; }
    public string SpecialAssignment { get; set; }
    public string SomeFutureProperty { get; set; }
}

Versus a key/value pair design which can be dynamic:

public class Employee
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<MetaKeyValue> Properties { get; set; }
}

public class MetaKey
{
    public Guid Id { get; set; }
    public string EntityType { get; set; } // could be a dictionary or enum
    public string Name { get; set; }
    public string Description { get; set; }
    public string Required { get; set; }
}

public class MetaKeyValue
{
    public Guid Id { get; set; }
    public Guid EntityId { get; set; }
    public Guid MetaKeyId { get; set; }
    public string Value { get; set; } // string isn't the preferred object type
}  

So, the debate is that I'm not sure which one is more efficient. The target persistence is a SQL database using Entity Framework. The beauty of the metadata design is that without modifying code and planning a deployment, new "properties" could be added to an entity and the values could be added and retrieved. The negative is that it's not what I'm accustomed to as I am an old-school coder who likes concrete classes that are statically defined. Would the dynamic design bite me in the rear later down the line?

clockwiseq
  • 4,189
  • 9
  • 38
  • 61
  • 1
    Probably a duplicate of the well-trodden EAV vs Relational question: http://stackoverflow.com/questions/870808/entity-attribute-value-database-vs-strict-relational-model-ecommerce-question – Ian Mercer Nov 16 '16 at 22:33
  • Is there a genuine case that your objects would have properties added to them on the fly? is it a functional requirement? if yes than go for it or else keep it simple. – Preet Singh Nov 16 '16 at 22:50
  • This is for a client that has already changed spec on me twice and it's only been a week since the initial discussion on design. I would prefer to design something for them so that they can add "extended properties" on the fly and not have to wait on me to make changes, QA, publish to UAT, and then get final approval. Thanks for the comments. – clockwiseq Nov 17 '16 at 14:06

0 Answers0