I am creating a mini-ORM to learn reflection better in C#.
Also I want to use Native & Pure C# and do not use Entity Framework or SQL Server Management Objects.
public static void CreateTable(Type tableType, string connectionString)
{
// codes to create table in database
}
The problem is the CreateTable
method, there are lots of problems in it, for example :
I could not find any standard way to create a table from user-defined class. How can I generate database tables from C# classes?: this solution is good but not ideal. Maybe it crashes in some situations.
DataTypes!
There is no integration between C# and SQL Server datatypes. For examplevarchar
,nvarchar
andtext
all are (or map to)string
!
So when a user creates this class :
public class Person
{
public int ID { get; set; }
public string Name { get; set; }
}
which SQL Server datatype should I use for Name
?
Finally if generating a SQL query and executing it is best way for this question, what is your suggestion?