Currently I am reading some documentations on creating web API using the Database first approach. I noticed that most of the tutorials migrate their table on their application. How do I make an web API that only expose or has one route to expose the table in a specific database using Entity Framework that no need data migration?
-
1. It's not quite clear what you are asking about 2. Remove any requests for documentation/tutorials/sample code.... just ask what you want to know / How to do what you want.Keith Nicholas– Keith Nicholas2020-01-29 02:53:49 +00:00Commented Jan 29, 2020 at 2:53
-
@KeithNicholas I made some edit. Thank you for pointing out.Ping– Ping2020-01-29 02:55:25 +00:00Commented Jan 29, 2020 at 2:55
-
you probably want stackoverflow.com/questions/41705235/…Keith Nicholas– Keith Nicholas2020-01-29 02:55:53 +00:00Commented Jan 29, 2020 at 2:55
-
1If you don't want to use the data migration feature, then don't use it. You don't have to. I've never used it.Gabriel Luci– Gabriel Luci2020-01-29 02:57:08 +00:00Commented Jan 29, 2020 at 2:57
-
1The question is still very unclear. Expose one table, database first, migrations.sramekpete– sramekpete2020-01-29 02:59:26 +00:00Commented Jan 29, 2020 at 2:59
2 Answers
You just need to download 4 from nugets and run Scaffold-DbContext command. Download these 4 from nugets.
1) EntityFrameworkCore
2) EntityFrameworkCore.Design
3) EntityFrameworkCore.Tools
4) EntityFrameworkCore.SqlServer
Open Tools > NuGet Package Manager > Package Manager Console. And enter this below in console.
Scaffold-DbContext "Server=yourserveraddress;Database=yourdatabase;user id=youruser;password=yourpassword;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
18 Comments
So I assume you are trying to create all the classes based on your existing database.
This is done with the Scaffold-DbContext command. You can use it manually as described here, but I prefer to use the EFCorePowerTools plugin. Use the Reverse Engineer feature, which will generate and run the appropriate Scaffold-DbContext command for you.