这是第一次使用实体框架。所以我不知道下一步该怎么做才能生成我的表格。
我创建了定义表所需的所有类。除了
ProjectContext.cs
类之外:
//using System.Data.Entity;
using Microsoft.EntityFrameworkCore;
using Projet.Models;
namespace Projet
{
public class ProjetContext : DbContext
{
public ProjetContext()
{
}
public ProjetContext(DbContextOptions options) : base(options)
{
}
....
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=;Database=;User Id=;Password=;TrustServerCertificate=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// ..
}
}
}
我在终端(Power Shell)中尝试了
add -migration
,导致了这个错误:
Add-Migration:术语“Add-Migration”不被识别为 cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
我安装了所有软件包:
这些是我正在使用的版本:
我在这里完全被封锁了。在检查数据库和模型之前,我不想继续创建控制器或视图,因为我仍然对此有一些疑问。
任何帮助将不胜感激。
使用 EF Core 的包管理器控制台,而不是 PowerShell 窗口 https://learn.microsoft.com/en-us/ef/core/cli/powershell
对于 PS 控制台,还有另一个工具集: https://learn.microsoft.com/en-us/ef/core/cli/dotnet