Reputation: 2711
Im using entity framework code-first in order to set up a database. This is my 2 classes i'd like to use as tables:
namespace NinjaNooking.Models
{
public class Frisorer
{
public int Id { get; set; }
public string Name { get; set; }
public List<Scheman> Schema {get;set;}
}
public class Scheman
{
public int Id { get; set; }
public int Schemat { get; set; }
public virtual Frisorer frisorer { get; set; }
}
}
Here is my context class:
namespace NinjaNooking.Models
{
public class Context : DbContext
{
public NameOfMyChoice?()
: base("DefaultConnection")
{
}
public DbSet<Frisorer> Frisorer { get; set; }
public DbSet<Scheman> Scheman {get;set; }
}
}
I was hoping that this would generate 2 tables in a database for me to acess with ssms, im using MVC and if I run the program a database gets created but my tables are not.
Connection string:
add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication3-20140312082008;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication3-20140312082008.mdf" providerName="System.Data.SqlClient" />
Upvotes: 0
Views: 90
Reputation: 1500
Replace your Connection String with following it greatly works for me
add name="DefaultConnection" connectionString="Data Source=(local)\sqlexpress;Initial Catalog=aspnet-MvcApplication3-20140312082008;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication3-20140312082008.mdf" providerName="System.Data.SqlClient" />
Upvotes: 1
Reputation: 17793
Are you actually running a query against the context? It may not create them until a query is run.
Also try renaming the variable Schema
Upvotes: 0