Is it possible to create a table model that depends on the user input ? Globally I'll get a List containing the column names of the table that I should create in the DB. The Question is how can I manage that as I don't know how many columns I must create.
The standard approach for a defined table (known structure) would be something like this:
[Table("TableName")]
public class TableName
{
[PrimaryKey, Identity] public int Id;
[Column] public string Name;
}
public void CreateTable(string configString)
{
using (var db = new DataConnection(configString))
{
db.CreateTable<TableName>();
}
}
Is it possible to create the table model dynamically, from something like this:
var userInput = new List<string>() { "Name", "Firstname", "Adresse", "Zipcode", "City" };
To get a model like this for the table creation:
[Table("TableName")]
public class TableName
{
[PrimaryKey, Identity] public int Id;
[Column] public string Name;
[Column] public string Firstname;
[Column] public string Adresse;
[Column] public string Zipcode;
[Column] public string City;
}
Thanks for any help :)