anesthetic
anesthetic

Reputation: 315

Dynamic table creation in .NET Core

So I'm having trouble determining how to add tables dynamically in a .NET Core web application. From my research it doesn't appear entity framework supports this feature. It's my understanding that EF is static, so all new tables would need to be created through migrations.

So I have 2 questions:

  1. Am I missing a way to add a table (say on a button click) using EF in spite of its static nature?
  2. If #1 is not possible, is there any other way to dynamically add a table other than use sql commands like CREATE TABLE..., like using Linq?

Upvotes: 2

Views: 1545

Answers (1)

galdin
galdin

Reputation: 14074

There's no way you can perform DDL tasks with EF.

You can however abuse the EntityFrameworkCore.Migrations API if you want to. The docs are here: https://learn.microsoft.com/en-us/ef/core/api/microsoft.entityframeworkcore.migrations

If you intend to do so, be warned that the migrations API is not meant to be used this way. So things like SQL injection, etc. will have to be handled manually as far as I know (unless things changed in the recent past).

Upvotes: 1

Related Questions