Carefully following Microsoft tutorial instructions (from a couple dotnet core examples). Problem: I get to the Add-Migration step and it works perfectly - except that in SQL Server, no database shows up.
So I tried pre-creating an empty database; no tables show up. Changed from trusted connection to user id and password. Still no luck.
I have Visual Studio 2017 v15.5.7
Steps: new project: Web Core application; this time took WebAPI option.
Nuget:
- Microsoft.EntityFrameworkCore.SqlServer (2.0.1)
- Microsoft.EntityFrameworkCore.Tools (2.0.1)
- Microsoft.VisualStudio.Web.CodeGeneration.Design (2.02)
Models.cs contains:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
namespace HunterDataCore.Models
{
public class HunterContext : DbContext
{
public HunterContext(DbContextOptions<HunterContext> options)
: base(options)
{ }
public DbSet<Behavior> Behaviors { get; set; }
}
public class Behavior
{
[Key]
public string BehaviorId { get; set; }
public string ProjectKey { get; set; }
[Required]
[MaxLength(200)]
public string Title { get; set; }
[MaxLength(500)]
public string Description { get; set; }
}
}
Startup.cs .. only changed one function:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var connection = @"Server=Puppy;Database=HunterDataCore;Trusted_Connection=True;ConnectRetryCount=0";
services.AddDbContext<HunterContext>(options => options.UseSqlServer(connection));
}
Then it says using Package Manage Console:
add-migration InitialCreate
It indeed adds a Migrations folder along with Initial Create: Up/Down/BuildTargetModel functions.
The UP function:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Behaviors",
columns: table => new
{
BehaviorId = table.Column<string>(nullable: false),
Description = table.Column<string>(maxLength: 500, nullable: true),
ProjectKey = table.Column<string>(nullable: true),
Title = table.Column<string>(maxLength: 200, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Behaviors", x => x.BehaviorId);
});
}
No runs, no hits, no errors, no one left on base -- and NO database or if I pre-add it, the database does NOT contain any new tables.
Any thoughts?
Thanks in advance.