DataConnector | ComponentOne
In This Topic
    Scaffolding
    In This Topic

    At times, without the controls and designers that make configuration easy, designing applications in DataConnectors requires some extra effort. With the scaffolding feature for DataConnectors, you'll find that creating applications with DataConnector is much easier.

    For data connectors, scaffolding generates relevant model classes based on the source entities and also creates the DbContext class. Let's walk through how to get started with the scaffolders.

    Create a Console App

    1. In Visual Studio, select Create a new project from the Get started pane.
    2. In the Create a new project dialog, select Console App, and click Next.

      Save app
    3. In the Configure your new project dialog, provide name of the project you want to create in the Project name field and location for the project in the Location field. Click Next.
    4. In the Additional information dialog, select the target framework from the Framework dropdown, if required and click Create. By default, the selected framework is .NET 6.0.

    Add the NuGet packages

    1. In the Solution Explorer, right click Dependencies and select Manage NuGet Packages.
    2. In NuGet Package Manager, select nuget.org as the Package source.
    3. Search and select the following packages and click Install.
      • C1.EntityFrameworkCore.Salesforce
      • Microsoft.EntityFrameworkCore.Tools (version 3.1.0)
      Note: If you are using the scaffolding for 2020 v3 or prior versions, select C1.EntityFrameworkCore.Salesforce & Microsoft.EntityFrameworkCore.Tools (version 2.1.0).

    Initialize the Scaffolder

    Follow the steps provided below to learn and implement Scaffolding using ADO.NET provider for Salesforce. Similar steps can be used to implement scaffolding in other DataConnectors as well.

    1. Go to View -> Other Windows -> Package Manager Console from Visual Studio
    2. Run scaffolding command line with the following syntax to generate single table from the datasource.
      C#
      Copy Code
      Scaffold-DbContext "Username=****;Password=****;Security Token=****;OAuth Client Id=****; OAuth Client Secret=*****; OAuth Token Endpoint=https://ap17.salesforce.com/services/oauth2/token; Url=https://ap17.salesforce.com/services/data/v42.0" C1.EntityFrameworkCore.Salesforce -OutputDir "GeneratedCode" -Tables Account
      

      The above command line generates .cs files to represent the entity framework model for the "Account" table in the Salesforce datasource.

    3. Run scaffolding command line with the following syntax to generate two tables from the datasource.
      C#
      Copy Code
      Scaffold-DbContext "Username=****;Password=*****;Security Token=****;OAuth Client Id=******; OAuth Client Secret=******; OAuth Token Endpoint=https://ap17.salesforce.com/services/oauth2/token; Url=https://ap17.salesforce.com/services/data/v42.0" C1.EntityFrameworkCore.Salesforce -OutputDir "GeneratedCode" -Tables Account, Order
      

      The above command line generates .cs files to represent the entity framework model for the "Account and Order" table in the Salesforce datasource.

    4. Run scaffolding command line with the following syntax to generate all tables in the datasource.
      C#
      Copy Code
      Scaffold-DbContext "Username=****;Password=****;Security Token=****;OAuth Client Id=****; OAuth Client Secret=*****; OAuth Token Endpoint=https://ap17.salesforce.com/services/oauth2/token; Url=https://ap17.salesforce.com/services/data/v42.0" C1.EntityFrameworkCore.Salesforce
      

      The above command line generates .cs files to represent the entity framework model for the all tables in the Salesforce datasource.