Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Not Generating Database by using Code first. here my code
C#
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
C#
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; }

  }
}


XML
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
Comments
[no name] 14-Sep-12 12:52pm    
So where is the code that creates the database?

1 solution

Hi, You need to add a connection string with the name 'MyContext'.

Hope this helps...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900