Can't Get EF 6 Code First To Create the Tables

ef-code-first entity-framework entity-framework-6

Question

The tables in my database exist independently of EF. However, I want the tables that EF will use to be generated automatically.

public class SessionInfo
{
    public Guid Id {get;set;}
    public string Name { get; set; }
    public DateTime StartsOn { get; set; }
    public DateTime EndsOn { get; set; }
    public string Notes { get; set; }
}

public class StudentsDbContext:DbContext
{
    public StudentsDbContext():base("name=memory")

    {
        Database.Log = s => this.LogDebug(s);         

    }

    public DbSet<SessionInfo> Sessions { get; set; }
}

Due to the absence of the table SessionInfoes, this code merely throws an exception.

 using (var db = new StudentsDbContext())
 {
       db.Sessions.Add(new SessionInfo() {Id = Guid.NewGuid(), Name = "bla"});           
       var st = db.Sessions.FirstOrDefault();
 }

What must I do for EF to automatically build the "SessionInfoes" table (or whatever name it goes by, it doesn't matter)? I believed that when the context is first used for a change or a query, Ef will build the tables.

Update

After some investigation, it appears that EF and Sqlite don't get along well; at most, EF can be used to perform queries. No entities are added, no tables are created.

1
0
8/5/2014 12:21:55 AM

Accepted Answer

ZZZ_tmp
1
5/23/2017 12:23:47 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow