Just curious if anybody does this or not, and how they may handle this differently.
This is probably my third project where I've leveraged this type of implementation where I:
- Create a plugin in designer to create a property for each entity type / view / typed list / stored proc that holds a unique integer for that entity (the plugin just assigns the next integer across all elements of the same type if a value hasn't already been added)
- Create a custom template that gets executed to override the constant enums templates so that enums (EntityType, TypedViewType, and I also add a TypedListType) give each item a unique value
public enum EntityType: int
{
Customer = 4
Group = 2,
Order = 3,
Person = 1,
}
- This is particularly useful when using CTE queries and/or easily storing information in generic tables (like config settings managed by admins and/or users per entity), where you can have one column be the EntityTypeId, and an another EntityId, and you can have a true PK to pass around too across the entire database and stored as perma-key in external systems too (i.e.: 1/2 => typeid=1/pkid=2, in the case above Person entity with id 2)
I've thought to myself that it would be nice to have something in the designer where I could just easily check a box and it cache the int values of the enums (if desired, default would be not to as it does today for good reason) out of the box. It works fine doing it with a plugin and a template override, but I figured I'm probably not the only one that's needed this, or found a way to do this. Or are others just doing this type of thing by using the Name of the entity? Note, I don't abuse this, as I realize leveraging this EAV model type of anti-pattern isn't always the best thing to do, but it does come in extremely handy once in a while (also for storing stuff in search indexes for example).
Just curious, thoughts? Good idea? Bad idea? Good design? Bad design?