Model Generation

Table Of Contents

Create Your Model From A Database

Fire up your Sharp Factory App and click on Add.

Click Add on the main screen

Common Settings

This screen only shows if it is the first model in your project. The Sharp Factory Framework supports multiple models in a single Model Container. This screen contains settings that are shared across all models in your project.

  1. Use Root Namespace in Project Name: When checked the names of the Class Library Projects generated will be prefixed with the namespace specified.

  2. Root Namespace: Specify the namespace that will be root for all C# code generated.

  3. Dependencies Folder: The name of the folder under which the code will be generated. The projects will be generated inside this folder in Visual Studio.

  4. Indentation: The number of spaces used to indent the generated C# code.

Click Next.

Common Settings

Connection Info

Enter your database server information in this screen. You will also specify your model name here. Please take into account that this is not the connection string that will be used by your application. This is just the connection string used by The Sharp Factory App to explore your database in order to generate the C# code.

  1. Enable Integrated Security: If enabled integrated security will be used to connect to the database to generate your model.

  2. Model Name: This is the name of the model in the generated C# code. Remember that you can have multiple models thus giving a meaningful name here is useful to later identify which model you are calling in your code.

  3. SQL User: This is the SQL Server User that will be used in the connection. This field is only available if Enable Integrated Security is not checked.

  4. Password: This is the SQL Server User's password that will be used in the connection. This field is only available if Enable Integrated Security is not checked.

  5. SQL Server: Specify the SQL Server where your database resides.

  6. Database dropdown: When the connection information is correct this dropdown will be populated with all the available databases in the server. Choose the one you wish to use in your model.

Click Next.

Connection Info and Model Name

Database Objects

Now it is time to choose the database artifacts you wish to import into your model. You can choose: Tables, Views, Stored Procedures, Functions, Sequences. The objects appear organized by object type, schema, object name.

Click Next.

Database Objects

Generating The Model...

Once you choose the objects you wish to import and click Next a screen will output a progress report.

Generating Model Progress

Model Details

Once the model has been generated; you will be taken to the Model Details screen. This screen is where you can manage all the models in your project and perform tasks like generating the C# code.

Model Details

Saving The Model

After generating the model you should click Save and choose a folder to save to. We recommend you save your model file inside the Visual Studio Solution folder where the code is going to be generated.

You could save the model to a different location if you wish to reuse the model across multiple Visual Studio Solutions.

Save Your Model

Once the model has been saved the full path to the model container file will be shown on the title bar of the screen.

Sync To Visual Studio Solution

Now that you have a model it is time to generate the C# code. The application will create all the projects if they don't exist. Otherwise, it will refresh or update the code. From the Model Details screen choose your model in the dropdown then click on Sync.

Sync your code

Choose Target Solution

After clicking Sync you are prompted to choose the Visual Studio Instance. In order to generate the C# code an instance of Visual Studio must be running with an open solution.

Click Next.

Choose Target Solution

Choose .NET Version

Choose one of the available versions of .NET to be used when generating the C# code.

Click Next.

Choose .NET Version

Entity Data Model JSON

The Sharp Factory Framework uses a proprietary JSON based format to store the model information. The extension of the file is .edmj. EDMJ stands for Entity Data Model JSON. It is a very lightweight format that ensures high performance for generating new models and parsing existing ones; even with hundreds or thousands of tables (or other database objects).

Next Steps

Now that you have generated all your code you will want to setup your application to consume the generated code. For more information got to Project Setup. There you will find how to configure your application to start interacting with your database using the generated C# code.