I am looking for a way to autogenerate a crud layer in asp.net core. I have a set of tables and I would like to expose this data through REST. There are a few hundred entities.
I dont really want to have to code each one manually, but instead, I would ideally like to generate crud for each entity (either code generation before hand or at runtime). This will satisfy about 80% of my cases.
Whats the easiest way to do this? I have looked at odata, but It look like I need to set up a controller for each entity (not ideal)…
I do remember dynamic data existing years ago for asp.net (not core) but this doesnt seem to be around anymore.
Any suggestions/comments are all welcome 🙂
You can expose an odata endpoint over an entity framework core model “Experimenting with OData in ASP.NET Core 3.1 | OData” https://devblogs.microsoft.com/odata/experimenting-with-odata-in-asp-net-core-3-1/
You can generate the entity framework classes from your database using a scaffolding “Entity Framework Core with Existing Database” https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx
You can look at this repository for a way to write a generic controller that handles crud requests to a db context in a generic way: Mocoding.AspNetCore.ODataApi https://github.com/mocoding-software/odata-api/
The term for that is scaffolding. There might be a template or there for sql, but the built in scaffolding in .net had been for models I think. I’d also wonder how the scaffolder would handle things like a service or repository class though. It might not work as well as you think
Not sure if there is a template that I can use for scaffolding all this but that would be a good start….