1
Answer

EF 4.1 CodeFirst Database is not create!!!

Hello everyone!

I need help on my project.

I have two classes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Classes
{
    public class Blog
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string BloggerName { get; set; }
        public List<Post> Posts { get; set; }
        public string BlogCode
        {
            get { return Title.Substring(0, 1) + ":" + BloggerName.Substring(0, 1); }
        }
    }

        public class Post
        {
            public int Id { get; set; }
            public string Title { get; set; }
            public string Content { get; set; }
            public virtual Blog Blog { get; set; }
        }

    }


The second class is

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using Classes;

namespace DataLayer
{
    public class Context:DbContext
    {
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }
    }
}


Also I ConsoleApplication:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Classes;
using DataLayer;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            CreateBlog();
        }
        public static void CreateBlog()
        {
            var blog = new Blog { BloggerName = "Mahir", Title = "Entity Framework Code First" };
            var db = new Context();
            db.Blogs.Add(blog);
            db.SaveChanges();
        }


    }
}


ConsoleApplication is Set as StartUp Project.
SQL server Management Studio is run.

When I run ConsoleApplication in SQL Server Management Studio should make a database.
Unfortunately it is not made.

Can we for some help to solve this problem and that the database is made?

Thanks in advance!
Answers (1)