none
Tables are not created in codefirstnewdbsample RRS feed

  • Question

  • hii

    I have also created same application(sample entity example,Blog and Post) and my databse is created but tables are not getting created.What should I do?

    Any Solution??

    Please mail me solution on my email ASAP,

    rahul.phatkare@outlook.com

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.Entity;
    
    namespace codefirstnewdbsample
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (var db = new BloggingContext())
                {
                    Console.Write("Enter name of blog:");
                    var name = Console.ReadLine();
                    var blog = new Blog { Name = name };
                    db.Blogs.Add(blog);
                    db.SaveChanges();
    
                    // Display all Blogs from the database 
                    var query = from b in db.Blogs
                                orderby b.Name
                                select b;
    
                    Console.WriteLine("All blogs in the database:");
                    foreach (var item in query)
                    {
                        Console.WriteLine(item.Name);
                    }
    
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey(); 
    
                }
            }
        }
        public class Blog
        {
            public int BlogId { get; set; }
            public string Name { get; set; }
    
            public virtual List<Post> Posts { get; set; }
        }
        public class Post
        {
            public int PostId { get; set; }
            public string Title { get; set; }
            public string Content { get; set; }
    
            public int BlogId { get; set; }
            public virtual Blog Blog { get; set; }
        }
        public class BloggingContext : DbContext
        {
            public DbSet<Blog> Blogs { get; set; }
            public DbSet<Post> Posts { get; set; }
        }
    
    }
    

    • Moved by CoolDadTx Monday, May 18, 2015 4:58 PM EF related
    Monday, May 18, 2015 3:55 PM

All replies