을 사용하여 경관을 감상 할 수있는 컨트롤러를 생성하십시오 DbContext를 만드는 동안 오류가 발생했습니다 내가 프로젝트 asp.net 코어를 사용하지만 내가 모델에 대한 뷰 컨트롤러를 생성 할 때 오류가 Asp.net 코어
인스턴스를 사용하여 모델을 가져옵니다. 이 개체에 대해 정의 된 매개 변수없는 생성자가 없습니다. 이 개체에 대해 매개 변수가없는 생성자가 정의되지 않았습니다. Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute에서 Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b__6_0()에서 (문자열 [] 인수) Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute (문자열 [에서 이것은 DBContext] 인수)
이다
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using WebApplication.Models;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using MySQL.Data.EntityFrameworkCore.Extensions;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
namespace WebApplication
{
public class HunterViewContext : DbContext
{
public HunterViewContext(DbContextOptions<HunterViewContext> options)
: base(options)
{ }
public DbSet<User> User{ get; set; }
}
}
DBContextFactory :
using Microsoft.EntityFrameworkCore;
using MySQL.Data.EntityFrameworkCore.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication.Models
{
public static class HunterViewContextFactory
{
public static HunterViewContext Create(string connectionString)
{
var optionsBuilder = new DbContextOptionsBuilder<HunterViewContext> ();
optionsBuilder.UseMySQL(connectionString);
//Ensure database creation
var context = new HunterViewContext(optionsBuilder.Options);
context.Database.EnsureCreated();
return context;
}
}
}
모델 :
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
namespace WebApplication.Models
{
public class User
{
public User()
{
}
public int Id { get; set; }
[MaxLength(30)]
public string Name { get; set; }
[MaxLength(50)]
public string LastName { get; set; }
}
}
내가
예, 저는 컨트롤러 클래스와 뷰를 자동으로 생성하는 Visual Studio 코드 스 캐 폴딩 기능을 사용하려고합니다. 그래서 뷰가있는 컨트롤러를 만들 수는 없지만 뷰가없는 컨트롤러를 만들 수는 있습니다. 오류. 그래서보기의 생성에 문제. –
ASP.NET Core의 경우 Visual Studio의 스 캐 폴딩 기능을 사용하려면 mvc 코드 생성기 및 도구 패키지를 종속 요소로 추가해야합니다. 같은 대답을 편집하여 도움이되기를 바랍니다. –
[ASP.NET 코어에서의 스캐 폴딩] (https://code.msdn.microsoft.com/Scaffolding-ASPNet-Core-MVC-1e9183fd) 뷰를 사용하여 컨트롤러를 생성하지만 이전과 같은 오류가있었습니다. –