This is my attempt to create new tables using code-first. My objective is to have a Name
table with a relation to the PhoneNumber
table. It actually does nothing to the database, so I must be missing something important.
My project is the default ASP MVC app.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace ZeroCloud1.Models
{
//included in ApplicationDbContext // public virtual DbSet Blogs { get; set; } // public virtual DbSet Posts { get; set; }
public partial class Blog
{
public Blog()
{
Posts = new HashSet<Post>();
}
public int BlogId { get; set; }
[StringLength(200)]
public string Name { get; set; }
[StringLength(200)]
public string Url { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
public partial class Post
{
public string PostString { get; set; }
public int ID { get; set; }
}
}
PM> Add-Migration 'TestClass3' Scaffolding migration 'TestClass3'. The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration TestClass3' again.
PM> Update-Database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Applying explicit migrations: [201704091548342_TestClass3]. Applying explicit migration: 201704091548342_TestClass3. Running Seed method.