How to add a database field to a table dynamically using MVC and Entity Framework using .Net?

I am developing a .NET application and have an accessible database. I have a category class:

public partial class Category
{
   public int CategoryId {get;set;}
   public string CategoryName {get;set;}
}

How to add dynamic fields to this model and, therefore, to the database? if this is not possible, is there any other way to solve my problem?

I allow the user to add his desired custom fields to add. So my database schema is getting

Category (CategoryId, CategoryName, CustomField1, CustomField2);

How to do it with EF 5 and MVC? Or can we do it another way?

+4
source share
1

, , - .

Category , CustomField. ,

public partial class Category
{
   public int CategoryId {get;set;}
   public string CategoryName {get;set;}
   public IList<CustomField> CustomFields {get;set;}
}

public class CustomField
{
   public int CustomFieldId {get;set;}

   public string FieldName {get;set;}
   public string FieldValue {get;set;}

   [ForeignKey("Category")]
   public int CategoryId {get;set;}
   public Category Category {get;set;}
}
+4

Source: https://habr.com/ru/post/1533734/


All Articles