Reverse Engineering (Scaffolding)
Reverse engineering (also called scaffolding) streamlines EF Core model creation by automatically generating context and entity classes from your LinkedIn schema. This includes a CDataContext class that extends DbContext and exposes DbSet properties representing available tables and views.
Scaffolding
Scaffolding is performed using the Package Manager Console (PMC) in Visual Studio. The following commands demonstrate how to scaffold EF Core models from your live LinkedIn data source.
Scaffold All Tables
Use the following command to scaffold all tables and views into a Models folder:
Scaffold-DbContext "InitiateOAuth=GETANDREFRESH;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:portNumber;CompanyId=XXXXXXX" CData.EntityFrameworkCore.LinkedIn -OutputDir Models -Context LinkedInContext
Scaffold A Subset of Tables
You can refine the scaffolding process to only create classes for a limited selection of tables.
This is useful when a large schema is taking a long time to scaffold due to the large number of classes it has to generate.
This is accomplished by specifying the tables/views that you want to scaffold at the end of your Scaffold-DbContext command in the PMC.
Scaffold-DbContext "InitiateOAuth=GETANDREFRESH;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:portNumber;CompanyId=XXXXXXX" CData.EntityFrameworkCore.LinkedIn -OutputDir Models -Context LinkedInContext -Tables CompanyStatusUpdates
Updating your Data Model
To refresh an existing model with updated tables or schema changes, add the -Force argument to your scaffolding command. This overwrites any previously generated model files.