MIT’s blog

個人的なメモかな

Microsoft.EntityFrameworkCore

次々と見つかるEntity Framework 6との違いorz Key属性は全てやり終えて、いざミグレーションって今度は

The entity type 'クラス' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.

と言われる。Entity Framework 6では何の指定もしなくても行けてたのにorz これ、ある記事(C#での説明でしたが)には単にクラス宣言に[Owned]付けるだけで解決したってあったので試してみましたが、「ステートメントをメソッドの外側に置くことは出来ません」となり、またまたOnModelCreatingのオーバーライド内に追加する方法を取ることにしました。

modelBuilder.Entity(Of エンティティ)().OwnsOne(GetType(クラス), 該当メンバー)

って感じにVisual Basicではなる様です。C#のサンプルではTypeOfとか使ってたので、VBでも全く同じキーワードがあるのでそのままやろうとしたら、全然違うものだと。

 

2021/12/13 0:43追記

あまりの量なのでもう一度Ownedについて調べ直してみると、Visual Basicでは

[Owned]

ではなく

<Owned>

なのが判明(*^^)v

 

しかし、ここで大きな問題が! 全ての問題をクリアしてこれでやっとミグレーション完了かと思いきや、今更な事態に愕然とするorz

The projedct language 'VB' isn't supported by the buil-in IMigrationsCodeGenerator service. You can try looking for an additional NuGet package which supports this language; moving your DbContext type to a C# class library referenced by this project; or manually implementing and registering the design-time service for the programming laguage.

Microsoft.EntityFrameworkCore.ToolsはVisual Basicには対応してないんだとorz