私はMicrosoft Visual Studio 2017コミュニティをインストールしたばかりで、最新のテクノロジに目を向けようとしています。エンティティフレームワークコア1.1と移行
私はまだMVCに精通しておらず、EF Core 1.1についてよく知らない人です。
ASP.NETコアとEFコアのPluralsightでいくつかの講座を受講しましたが、これらのレコーディング以降に変更が加えられているようです。
私はデータベースに接続するには、「Inital-の移行を追加」を実行すると、私は常に取得:
のSystem.InvalidOperationException:エンティティタイプ「カテゴリー」を定義する主キーが必要です。 Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.ValidateでMicrosoft.EntityFrameworkCore.Internal.ModelValidator.Validate(IModelをモデル) でMicrosoft.EntityFrameworkCore.Internal.ModelValidator.ShowError(文字列メッセージ) (IModelをモデル) でMicrosoft.EntityFrameworkCoreでMicrosoft.EntityFrameworkCore.InternalでMicrosoft.EntityFrameworkCore.Internal.DbContextServices.CreateModelでSystem.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey key, Func
2 ValueFactoryので.Infrastructure.ModelSource.CreateModel(DbContextコンテキスト、IConventionSetBuilder conventionSetBuilder、IModelValidatorバリ) ) () 。 LazyRef 1.get_Value() at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0
1.b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.Opera actionBase.Execute(アクションアクション) エンティティタイプ 'Category'では、主キーを定義する必要があります。ここで
は、いくつかの関連するコードです:
Category.cs
public class Category
{
[Key]
public int CategoryId;
public String CategoryName;
}
ICategoryRepository.cs
名前空間Dokumentbasen6.Model { IEnumerableをカテゴリーは{取得ICategoryRepository { パブリックインターフェイス。 } カテゴリGetCategoryById(int CategoryId); }}
CategoryRepository.cs
namespace Dokumentbasen6.Model
{IEnumerableをカテゴリ{得るICategoryRepository
{ パブリックインターフェース。 } カテゴリGetCategoryById(int CategoryId); }}
DokumentbasenContext.cs
public class DokumentbasenContext : DbContext
{
public DokumentbasenContext(DbContextOptions<DokumentbasenContext> options) : base(options)
{
}
public DbSet<Document> Dokuments { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Standard> Standards { get; set; }
public DbSet<Member> Members { get; set; }
}
私は.NETCoreApp 1.0ターゲットフレームワークを使用しますが、私は今.NetCoreApp 1.1にターゲットフレームワークを変更したプロジェクトをビルドします。
事前にサポートいただきありがとうございます。
敬具、
ジョンホーコンAriansen