I’m using c# and System.Data.SQLite
I have some classes I want to generate as tables in SQLite at runtime, but I don’t want to hardcode the SQL string for each class.
I was wondering, what is the best method to do this?
I tried adding attributes to my class and class properties hoping there would be something that would create the SQL string for me but…
Here’s an example:
[Table(Name = "tblDocument")]
public class Document
{
[Column(IsPrimaryKey = true, IsDbGenerated = true)]
public long DocumentId { get; set; }
[Column(CanBeNull = true)]
public string File { get; set; }
}
To create this as a table in SQLite I need to generate something like:
string CreateSqlString =
@"CREATE TABLE [tblDocument] (" +
@"[DocumentId] INTEGER PRIMARY KEY NOT NULL," +
@"[File] TEXT NOT NULL)";
Thanks in advance.
Are you maybe looking for something like SubSonic. It can be run with migrations turned on and that will generate tables for your classes.
Assuming you have referenced Castle.Core.dll, SubSonic.Core.dll and System.Data.SQLite.DLL
App.config should be