Repositories

Table Of Contents

Repository Classes

The Sharp Factory App generates one repository class per entity. Each repository is tailored based on the characteristics of the particular entity.

For example, it takes into account if the entity has primary key or unique keys. And whether those keys are composed of multiple fields, like a multi-column primary key.

Because many factors are taken into account the generating repositories might differ from one another, but follow a similar pattern in general.

Each repository is named the same as the entity. So for example the repository for the Customer entity will be named Customer

Repository Container Class

The RepositoryContainer class contains all the repositories in the system grouped by models.

In order to interact with the data store an instance of this class is required.

The RepositoryContainer class lives under the following namespace:

{Root Namespace}.Repository.Container

Where "Root Namespace" is the namespace specified by the developer the first time the Model was added to your project.

The repositories are organized in the following pattern:

RepositoryContainer.{Model Name}.{Sql Schema Name}.{Entity Name}.{Method Name}

So for an entity called Customer we would access the ToList method like this:

C#
// first declare an instance of

// the RepositoryContainer class

var repo = new RepositoryContainer();

// call the ToList method on the

// Customer entity

var customers = repo.AppDbModel.Sales.Customer.ToList();

Notice in the previous example:

  • AppDbModel is the name given to the model when it was created.

  • Sales is the name of the Sql Schema under which the object resides in the Sql Server.

  • Customer is the name of repository which matches the name of the entity.

  • ToList is the name of method that returns a list of entities.

This pattern makes it intuitive for any developer to work with many databases (models) and many entities per model.

Also it becomes even easier due to the fact that the developer can take advantage of intellisense and auto completion when using Visual Studio.

The Sharp Factory Framework is strongly typed and never requires passing around hard-coded strings for interacting with the entities. This is different from other Object Relational Mappers in the market.