Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
Not Generating Database by using Code first. here my code
namespace EFfistSample
{
    class Program
    {
        static void Main(string[] args)
        {
            var person = new Person { FirstName = "Sreekanth", LastName = "Vankamamidi", BirthDate = DateTime.Now };
            using (var context = new MyContext())
            {
                context.Persons.Add(person);
                context.SaveChanges();
            }
            Console.Write("Person Saved");
            Console.ReadLine();
        }
    }
}
 
person.cs
namespace EFfistSample
{
  public class Person
    {
      public int PersonID { get; set; }
      public string LastName { get; set; }
      public string FirstName { get; set; }
      public DateTime BirthDate { get; set; }
 
  }
}
 
namespace EFfistSample
{
   public class MyContext : DbContext
    {
       public MyContext()
       { }
 
       public DbSet<Person> Persons { get; set; }
    }
}
 
here it should generate database in sqlserver but it's not generating. plz help me
thank you.
Posted 14-Sep-12 1:35am
sree561.1K
Comments
Wes Aday at 14-Sep-12 12:52pm
   
So where is the code that creates the database?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi, You need to add a connection string with the name 'MyContext'.
 
Hope this helps...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 450
1 OriginalGriff 230
2 DamithSL 150
3 Dave Kreskowiak 110
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,740
1 DamithSL 5,644
2 Sergey Alexandrovich Kryukov 5,404
3 Maciej Los 5,011
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 23 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100