Click here to Skip to main content
12,621,302 members (32,218 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET4
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
Comments
Wes Aday 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161128.1 | Last Updated 23 Sep 2012
Copyright © CodeProject, 1999-2016
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