This question has already been answered:

Hello, I have a question about adding fields to the database table, using the code (for example, in the admin site for the product).

Is it possible to implement such functionality, for example, for the "Phone" product, add a year of release field with the same admin panel? Where should I go with the search for the answer and examples (maybe even the right search queries =))?

Technology stack: C # (ASP.NET MVC + Entity Framework)

Thank you all for the tips / answers.

Reported as a duplicate by Pavel Mayorov c # 5 Jul '17 at 12:21

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • 3
    It is worth moving in the opposite direction from such ventures - Sergey

1 answer 1

There were already similar questions on the site, from the last one I remember it:

EF is not intended for this, the main sharpening is for the migration mechanism (not in runtime).

If you want to add additional fields in the admin panel, then design additional tables in the database structure with a description of the fields and their values.

And already in rantayme that it was necessary to insert only into ready tables.

  • And if you don’t add a field to the "Phone" entity itself, and for example make an AdditionalInfo: string field in it, which will store a JSON object with additional fields? The idea seems to me so-so but still. Or another table with fields, but I have no idea how to implement it correctly, but I don’t really want to write a fierce ** code =) - Bogdan Stefanjuk
  • @BogdanStefanjuk The duplicate link briefly describes the EAV approach. And for any universality you have to pay. What - this is for you to choose. In EAV and JSON, you deliberately open up part of the functionality of the database - indexes, triggers, giving up the EF lose convenient modern ORM mechanisms ... The choice is yours. - AK