Код: Выделить всё
Add-Migration initialMigration
Найдено более одного DbContext с именем «ApplicationDbContext». Укажите, какой из них использовать, указав его полное имя в точном регистре.
Вместо этого я пытался использовать это:
Код: Выделить всё
Add-Migration InitialCreate -Context ApplicationDbContext
Код: Выделить всё
namespace Playersmanagementsystem.Models
{
public class Player
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Emailaddress { get; set; }
public int PhoneNumber { get; set; }
}
}
Код: Выделить всё
using Playersmanagementsystem.Models;
namespace Playersmanagementsystem.Context
{
public class ApplicationDbContext :DbContext
{
public ApplicationDbContext(DbContextOptions options)
: base(options)
{
}
public DbSet
Players { get; set; }
}
}
Код: Выделить всё
{
"ConnectionStrings": {
"DefaultConnection": "Server :DESKTOP-DFBVCE0;Database:Players; User Id=Ammadlogin;Password:ammadpass1; TrueServerCertificate:True"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Код Program.cs выглядит следующим образом:
Код: Выделить всё
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Playersmanagementsystem.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services.AddDbContext(options =>
options.UseSqlServer(connectionString));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores();
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
app.Run();
В настоящее время моя цель — добавить мою первую миграцию для проигрывателя моделей. Спасибо
Подробнее здесь: https://stackoverflow.com/questions/791 ... y-which-on