Project Setup

Table Of Contents

Connection String

Before you can interact with the database from your application using The Sharp Factory Framework you will need to register the connection string.

Because multiple models are supported you will need to register one connection string per model in your project.

Registering The Connection String

We recommend registering the connection string(s) early in the execution pipeline.

For example in your Program.cs class; more specifically in your Main method. Or in the configured entry point for your application.

The Database.RegisterModelConnectionString takes 2 parameters:

  1. int modelId: The code generator assigns a unique model id to each model added to the model container. This can easily be accessed from the RepoLookup.ModelId static class.

  2. string connectionString: This is the connection string that your application will use during runtime to access the database.

The Repository Container

The RepositoryContainer class is the starting point for all data access and manipulation. This class does not keep any state. This means it can be used as a singleton and we recommend you do so. However you are not constraint to do so if you wish otherwise.

The code sample below register a connection string for a model called AppDb.

// Replace SFDemo with the root namespace

// specified when you first generated the model

using SFDemo.Repository.Common;
using SFDemo.Repository.Container;

namespace ConsoleClient
    class Program

        static void Main(string[] args)
            //Database is a static class

            //it was generated by The Sharp Factory App

            "Your Application's Connection String Goes Here");   
            //This is your repository container

            //Use it to perform operations against the data store

            var repository = new RepositoryContainer();