user11376624
user11376624

Reputation:

EF Core scaffold-dbcontext custom namespace

This is a follow-up to a similar question which was answered with a reference to this issue, which has since been closed and migrated to 2.1.0 milestone according to the linked page but I can't find it in there by searching for 'scaffold-dbcontext namespace'.

Are there any plans to allow the namespace to be specified when calling scaffold-dbcontext ? - I'm developing something DB-first and routinely re-scaffolding the schema. Each time I then need to search/replace [namespace].Models.Models to remove the second .Models - not a big deal by any means but if I could tell the scaffolder what namespace to use it'd be handy.

(I appreciate that the scaffolder is mainly intended to be used once to migrate to code-first then never needed again but due to reasons, that's not how I'm using it.)

(I would have added a comment to the original question, since this is essentially the same question but don't have enough reputation, so posted it as an answer, which was deleted, so am re-posting as a fresh question.)

Upvotes: 1

Views: 1810

Answers (2)

user11376624
user11376624

Reputation:

One answer is to move to VS 2019 16.8.0 preview / Net 5.0 preview 7 / EF Core 5.0.0 preview, which I just did - scaffolding now uses the namespace of the project, in my case .Models, which is exactly as I want it.

Upvotes: 0

acinace
acinace

Reputation: 114

In my case, i remarked Scaffold-DbContext works better in EF Core 3.1.5

Scaffold-DbContext 'Server=MSSQLSEVER;Database=MyDB_TEST;Trusted_Connection=True;' Microsoft.EntityFrameworkCore.SqlServer -ContextDir MyDB -Context MyDBContext  -OutputDir MyDB\Test -StartupProject Project -Force

I Obtain something like [ProjectNamespace].MyDB.Test

Upvotes: 2

Related Questions