I want to add tables to the SQLCe database at runtime because table names are not static and are known at compile time. I am trying to do this with Entity Framework 4.1 and DbContext as follows:
public class PersonContext : DbContext { public PersonContext() : base("UnicornsCEDatabase") { } } public class Person { public int NameId { get; set; } public string Name { get; set; } } public class Program { static void Main(string[] args) { using (var db = new PersonContext()) { db.Database.Delete();
When trying to run this, it throws this error: The object type of Person is not part of the model for the current context.
Is it possible to add a DbSet at runtime to a DbContext without to determine what the DbSet (with its schema) is in the database?
When defining DbContext statically with Person, EF will create the entire database and tables on the fly, which is great.
For instance:
foreach (var item in collection) { string tableName = "PersonTable_"+item.Name;
How is this possible with EF or do I need to create them using some other technique?
Thanks, Jurgen
source share