3

Evening.

I have to develop an api for an existing SQL Server 2017 database.

I need to use Microsoft Web API, and I would like to use Core 3.1 but I have read I have to use migrations and such, and i have been told not to build the api using migrations.

Would I be better using .Net Framework instead or is there a way to use Core without using migrations?

I hope that it's not too broad a question, but I really am struggling to make a decision so any feedback etc would be greatly appreciated.

carlson

Fei Han
  • 26,415
  • 1
  • 30
  • 41
carlson46uk4
  • 31
  • 1
  • 2
  • Web API is a web stack, not a data access technology or ORM. It doesn't perform migrations. You should be asking about *Entity Framework*, which has migrations both in .NET Old and .NET Core\ – Panagiotis Kanavos Oct 01 '20 at 06:21
  • Does this answer your question? [How can I disable code first migrations](https://stackoverflow.com/questions/14654055/how-can-i-disable-code-first-migrations) – Panagiotis Kanavos Oct 01 '20 at 06:23
  • Why are you asking though? EF Core [doesn't execute migrations automatically](https://github.com/dotnet/efcore/issues/3152) so you shouldn't have to do anything - just ensure you *don't* call `context.Database.Migrate()`. You need to do something to disable migrations only in .NET Old – Panagiotis Kanavos Oct 01 '20 at 06:26

1 Answers1

1

If you'd like to access data from an existing database and tables with Entity Framework (EF) Core in your ASP.NET Core Web API project, you can try to use Scaffold-DbContext command or dotnet ef dbcontext scaffold command to generate code for a DbContext and entity types for your database.

enter image description here

Besides, you can also install and use Microsoft.Data.SqlClient to access your existing SQL Server database in ASP.NET Core project.

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • 1
    The OP is asking how to *not* use migrations – Panagiotis Kanavos Oct 01 '20 at 06:22
  • `It doesn't perform migrations.` Hi @PanagiotisKanavos, as you mentioned, it does not require migration. About op's scenario "develop an api for an existing SQL Server 2017 database" I share how to access an existing db in ASP.NET Core. – Fei Han Oct 01 '20 at 06:26
  • 1
    One question is, if I don't use migration, how to ensure the code is in sync with database model updates apart from the obvious like adding a column. – Andes Lam Jul 09 '21 at 05:58