Create different TableS dynamically with only one class definition #165

Open
Perret opened this Issue Feb 18, 2013 · 4 comments

Comments

3 participants

Perret commented Feb 18, 2013

Hi

Is there any way to create different tables dynamically (i.e. without hardcoding many class definitions) based on one class (cause I don't think that new classes can be generated on fly), or at least same definition but with a different name?

Thanks

EDIT: and without using an command "CREATE TABLE " etc... i'm not sure if someone has suceeded to create Table suing some reflection tricks.

Owner

praeclarum commented Feb 21, 2013

I have been tempted to add explicit table names, so you could do something like:

db.CreateTable ("AlphaThings");
db.CreateTable ("BetaThings");
db.CreateTable ("GammaThings");

etc.

Would that help?

Perret commented Feb 22, 2013

Sometimes the table has to be created following a user definition, i.e the columns can't be hardcoded either.
Well maybe there is no solution and I'm stuck with old fashion Strings =/.

Maybe a first trick could be to have a decent syntax for creating different table based on the same schema but with different name using something like:
db.CreateTable("NameForThisTable")
But then I guess it would create bunches of problem for the other methods...
i.e. insert(MyClassDefinitionObject); //(but which table?)

Contributor

louy commented Mar 28, 2013

Did you try Inheritance?

public class MyClass
{
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
        [MaxLength(255)]
        public string Name { get; set; }
        // ...
}
public class MyClass2 : MyClass
{
}

Perret commented Apr 1, 2013

Yes but can you generate new inherited classes without hardcoding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment