2017-01-18 8 views
2

Visual Studio Community 2015 v 14.0.25431.01 Update 3とMS .NET Framework v 4.6.91586を使用してthis tutorialをフォローしていますが、コントローラをスキャフォールドしようとすると次のエラーが発生します。 、説明したよう:Entity Frameworkコア1.0スケジューリングされていないコントローラとビュー

Error

私はherehereが、無駄に提案されたすべての解決策を試してみました。はい、プロジェクトを再構築しようとしました。

ここに私のプロジェクトの関連コードがあります。

学生モデル:

using System; 
using System.Collections.Generic; 

namespace ContosoUniversity.Models 
{ 
    public class Student 
    { 
     public int ID { get; set; } 
     public string LastName { get; set; } 
     public string FirstMidName { get; set; } 
     public DateTime EnrollmentDate { get; set; } 

     public ICollection<Enrollment> Enrollments { get; set; } 
    } 
} 

SchoolContext:

public class SchoolContext : DbContext 
    { 
     public SchoolContext(DbContextOptions<SchoolContext> options) : base(options) 
     { 
     } 

     public DbSet<Course> Courses { get; set; } 
     public DbSet<Enrollment> Enrollments { get; set; } 
     public DbSet<Student> Students { get; set; } 

     protected override void OnModelCreating(ModelBuilder modelBuilder) 
     { 
      modelBuilder.Entity<Course>().ToTable("Course"); 
      modelBuilder.Entity<Enrollment>().ToTable("Enrollment"); 
      modelBuilder.Entity<Student>().ToTable("Student"); 
     } 

    } 

追加startup.csでのサービスへのSchoolContext:

public void ConfigureServices(IServiceCollection services) 
     { 
      // Add framework services. 
      services.AddApplicationInsightsTelemetry(Configuration); 

      services.AddDbContext<SchoolContext>(options => 
       options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 

そして、これはappSetting.jsonで私たconnectionStringです:

"ConnectionStrings": { 
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-ContosoUniversity-75b88406-9d10-4237-814a-3f725b9b4e3d;Trusted_Connection=True;MultipleActiveResultSets=true" 
    } 

答えて

1

私は、パラメータのないコンストラクタを持たないという問題を乗り越えることができました。 hereを示唆したように、私は単純なようDBContextクラスだけでなく、Modelクラスの両方にコンストラクタを提供:

public Student() { } 

今、私は別のエラーを取得しています。私は新しい質問としてそれを提示する必要があると思う。私はそれは価値があるものの、これはエラーログの一部です:

 Attempting to figure out the EntityFramework metadata for the model and DbContext: Student 
    Exception has been thrown by the target of an invocation. StackTrace: 
     at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 
     at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) 
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
     at Microsoft.AspNetCore.Hosting.Internal.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) 
     at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() 
     at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() 
     at Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore.EntityFrameworkServices.TryCreateContextUsingAppCode(Type dbContextType, ModelType startupType) 
    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) StackTrace: 
... 
    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 
    There is no entity type Student on DbContext ContosoUniversity.Data.SchoolContext at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,... 
+0

私のVS 2015のインストールは何らかの形で破損していました。再インストールされ、スキャフォールディングは完璧に動作しています - 非常に遅い場合(Railsと比較して)。 – PakiPat

関連する問題