I recently started to learn MVC and code first approach. I am using exact code as the sample example. But its not doing anything. It is not creating database.
here is the classes code.
public class Movie
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}
aithex2
Member
22 Points
50 Posts
MVC 3 - Code First is not creating Database
Dec 04, 2012 09:30 AM|LINK
Hi
I recently started to learn MVC and code first approach. I am using exact code as the sample example. But its not doing anything. It is not creating database.
here is the classes code.
public class Movie { public int ID { get; set; } public string Title { get; set; } public DateTime ReleaseDate { get; set; } public string Genre { get; set; } public decimal Price { get; set; } } public class MovieDBContext : DbContext { public DbSet<Movie> Movies { get; set; } }here is connection string
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
i have tried many other examples but no result. i just wanna know if i am missing anything
I am using Visual Studio 2012 and i haven't installed any SQL server.
i didn't install any Entity Framework package as its already available.
A Sage Programmer
EnenDaveyBoy
Participant
1465 Points
1146 Posts
Re: MVC 3 - Code First is not creating Database
Dec 04, 2012 09:39 AM|LINK
download and setup SQL server management Studio, which will allow you to see if the database is there.
What makes you think its not being created? And have you initiated it in the global.asa
ignatandrei
All-Star
134843 Points
21605 Posts
Moderator
MVP
Re: MVC 3 - Code First is not creating Database
Dec 04, 2012 10:30 AM|LINK
check the sdf existance with Windows Explorer, not Visual Studio
aithex2
Member
22 Points
50 Posts
Re: MVC 3 - Code First is not creating Database
Dec 05, 2012 01:22 AM|LINK
It's not even in windows explorer...
A Sage Programmer
aithex2
Member
22 Points
50 Posts
Re: MVC 3 - Code First is not creating Database
Dec 05, 2012 01:24 AM|LINK
Becuase it's not in windows explorer. and i didn't initiate in global.asax
how do i? and i don't want sample data, i was wondering there should be something that tells the EF to make db from the myContext : DbContext Class
A Sage Programmer
ignatandrei
All-Star
134843 Points
21605 Posts
Moderator
MVP
Re: MVC 3 - Code First is not creating Database
Dec 05, 2012 02:46 AM|LINK
just use it once.
aithex2
Member
22 Points
50 Posts
Re: MVC 3 - Code First is not creating Database
Dec 05, 2012 07:21 AM|LINK
how to use
A Sage Programmer
ignatandrei
All-Star
134843 Points
21605 Posts
Moderator
MVP
Re: MVC 3 - Code First is not creating Database
Dec 05, 2012 11:17 AM|LINK
using(MovieDBContext mdc=new MovieDBContext ())
{
int i =mdc.Movies.Count();
}
aithex2
Member
22 Points
50 Posts
Re: MVC 3 - Code First is not creating Database
Dec 06, 2012 04:17 AM|LINK
Thanks it works...
A Sage Programmer