I'll try to use CodeFirst model for creating dataBase.
Prepare code like below (from online tutorial). Code is exactly like in tutorial:
class Program
{
static void Main(string[] args)
{
using (BlogContext db = new BlogContext())
{
Console.Write("Enter a name for a new Blog:");
var name = Console.ReadLine();
var blog = new Blog { Name = name };
Database.SetInitializer<BlogContext>(null);
db.Blogs.Add(blog);
db.SaveChanges();
var query = from b in db.Blogs
orderby b.Name
select b;
foreach (var item in query)
{
Console.WriteLine(item.Name);
}
}
}
}
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 BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
}
As result - got exception
Solution for this exception found here. Now it's ok, work and show me saved data, but in my Sql Server Object explorer i can't see any database or table.
Any suggestion why? Wnat i must to do for repairing this?
Edit
So, as was mentioned by @Sergiy Berezovskiy - i try to check dataBase and add manually dataConnection for displaying just created dataBase.