I have a relational database with a number of entities. Example:
(source: https://www.researchgate.net/figure/A-sample-relational-database-schema_fig2_228999233)
What is the best (simple but safe) approach for the web-application to dynamically allow basic CRUD and List operations for the underlying data, without strict binding to the actual entities. So, if I define another entity in the database, my application will accommodate it with no additional coding.
I kicked off with MVC approach on ASP.NET, and now I doubt it was a good decision. So, in MVC I needed a way to read from the database the list of entities and based on that dynamically create appropriate controllers. Then I needed to read the attributes for those entities and dynamically build models, and finally my view shouldn't have been bound to the specific models, so it renders whatever dynamic model comes.
I ended up creating a type called Entity, that will have contain a dictionary of all fields that an entity has. This is the example
{
"Id": "7655b4ae-4495-485a-8a66-3be469700726",
"Name": "Contact",
"Attributes": [
{
"Type": "string",
"Value": "John",
"Name": "firstname",
"DisplayName": "First Name"
},
{
"Type": "string",
"Value": "Doe",
"Name": "lastname",
"DisplayName": "Last Name"
},
{
"Type": "date",
"Value": "1990-01-02T00:00:00.000Z",
"Name": "birthdate",
"DisplayName": "First Name"
}
]
}
There are some difficulties:
- It is hard to work with linked entities in the view
- I had to write my own ModelBinder, my own Dynamic Controller and a bunch of View- and Editor- Templates in order to support the model. This is a lot of custom code and it is not very neat and easy to work with
- This approach completely ignores one of the main benefits of MVC, which is data-validation done by the Model. In fact there's no data validation anymore and I have to write own validators for all possible types of fields.
I would like to hear your thoughts or ideas, or any links to further reading or projects that have already found a good solution. I am looking for ASP.NET/Core stack.