.NET Core EF 2.1 Scaffolding - DatabaseFirst - How to add more tables

3

I have a clean project solution (intended to be a .NET Core MVC app)

I have two prjects - Home.CorePoC.EntityModel and Home.CorePoC.Model I am calling dotnet cli from Home.CorePoC.Model.

The idea is that I want partial classes and logical separation from custom attributes and attributes from database.

I want to write a powershell script that I will be calling when I want to add/remove some tables, columns in tables etc.

In dotnet CLI when I add initially tables, it works just fine:

Scaffold-DbContext "Server=sqlServ2016;Database=TestDb;Persist Security 
Info=False;User ID=admin;Password=admin;" Microsoft.EntityFrameworkCore.SqlServer 
-Tables "Table1","Table2","Table3" -ContextDir "..\Home.CorePoC.EntityModel" 
-OutputDir "TestDB" -force -DataAnnotations -UseDatabaseNames

Now, when I want to add just more tables it work as well but I have an error message: "Cannot add 'Table4'. There is already a linked file in this folder with the same name." Also, I get error in cli console:

Exception calling "AddFromFile" with "1" argument(s): "A drag operation is already in progress (Exception from HRESULT: 0x80040103)"

Must I delete all files and then recreate it (linked file TestContext.cs that was initially created) or there is different way how to avoid this error message which is non-critical (I successfully added Table4 to my models).

I am planning to put this statement into powershell script wich it will be called from project folder (where I have installed nuget Microsoft.EntityFrameworkCore.Tools(2.1.4))

c#
asp.net-core
.net-core
entity-framework-core
asked on Stack Overflow Dec 4, 2018 by Stefan0309

1 Answer

2

That is because it will try and add the Context file for Table4 but is unable to as one already exists. There is already a feature request to update Entity Framework Core scaffolds rather than having to recreate them every time. You would have to override the generated entities each time by using the -Force flag

answered on Stack Overflow Dec 4, 2018 by Tubs

User contributions licensed under CC BY-SA 3.0