public string GenerateCreateTableSql<T>()
{
Type type = typeof(T);
string tableName = type.Name;
var properties = type.GetProperties();
var columnDefs = properties.Select(p => $"{p.Name} {GetDbType(p.PropertyType)}");
string sql = $"CREATE TABLE {tableName} ({string.Join(",", columnDefs)})";
return sql;
}
private string GetDbType(Type type)
{
if (type == typeof(int))
return "INT";
else if (type == typeof(string))
return "NVARCHAR(MAX)";
throw new NotSupportedException($"Type {type.FullName} is not supported.");
}