hanaim-devops / PriemChecker

0 stars 0 forks source link

Parameterloze constructor toevoegen in DB Context om Migrations te kunnen genereren (op 'Design time' (?)) #3

Open bartvanderwal opened 1 month ago

bartvanderwal commented 1 month ago

Om een error op te lossen gebruikte ik

dotnet add package Microsoft.EntityFrameworkCore.Design

Als ik daarna weer doe:

dotnet ef migrations add InitialCreate                 

krijg ik nu de error

Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions1[PriemCheckerLibrary.PriemCheckContext]' while attempting to activate 'PriemCheckerLibrary.PriemCheckContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

Hiervoor moet ik een parameterloze consdtructor toevoegen geeft ChatGPT aan (bij mij een vaag bekende oplossing uit een ver verleden, 2014 ofzo, in 10 jaar dus niks veranderd op dit punt?):

Edit: Ja toch wel. Je kunt nu ook een zogenaamde PriemCheckContextFactory aanmaken. Voor de design time variant. Doe ik dat. Wel bak boilerplate code.

bartvanderwal commented 1 month ago

Nu moet ik nog een EF COre SQLServer package installeren in PriemCheckLibrary lijkt het

Zie foutmelding op dotnet ef migrations add InitialCreate

/Users/bartvanderwal/Library/CloudStorage/OneDrive-HAN/MDO/PriemChecker/PriemCheckerLibrary/PriemCheckContextFactory.cs(11,24): error CS1061: 'DbContextOptionsBuilder<PriemCheckContext>' does not contain a definition for 'UseSqlServer' and no accessible extension method 'UseSqlServer' accepting a first argument of type 'DbContextOptionsBuilder<PriemCheckContext>' could be found (are you missing a using directive or an assembly reference?) [/Users/bartvanderwal/Library/CloudStorage/OneDrive-HAN/MDO/PriemChecker/PriemCheckerLibrary/PriemCheckerLibrary.csproj]
bartvanderwal commented 1 month ago

Deze installeer je met:

dotnet add package Microsoft.EntityFrameworkCore.SqlServer