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 :)
question from:
https://stackoverflow.com/questions/65890886/linq2db-create-dynamic-table-model 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…