Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / XML

Sharp RepoGen

0.00/5 (No votes)
7 May 2014CPOL2 min read 9.7K   94  
Sharp RepoGen is a simple tool to create repository interface having methods for CRUD operation and its implementing class. Using this tool easily you can generate your repositry class and interface. Code is generated with the help of xml template, so very easily you may change the template to creat

Sample Image - maximum width is 600 pixels

Introduction

If you are planning to use Repository pattern in your project, then 'SharpRepoGen' is definitely going to be a best help for you. Using this you may avoid creating the similar pattern Repositry Classes and its interfaces. Using this tool easily you can generate your repositry class and interface. Code is generated with the help of xml template, so very easily you may change the template to create your source code as per your requirement. Section Tools, Design Pattern

Background

Repository Design pattern now a days has become very popular. This tool helps to implement the same without much effort.

Using the Code

Tool does most of the things for you, you simply need to provide your database credentials for which you want to create CRUD.

You simply need modify Template xml (basic setting done) to achieve your own naming conventions and coding standards.

Download the demo project and unzip the downloaded file.

  • You will see SharpRepoGen.exe file, double click it to Run.
  • Enter your database credentials and hit login.
    Image 2
  • You will be redirected to a new screen where, you will see your database tables on the left.
  • Select your tables for which you want to generate the repository classes. Use Ctrl + A and Ctrl + N to Select All/ Select None.
    Image 3
  • Hit F5 to generate the repository classes.
  • Select appropriate radio button Interface/ Repository Classes to see the files generated. You may click on file name to preview the same.
    Image 4
  • Hit Ctrl + T to modify the template if you want to modify the template.
    Image 5

    As discussed earlier, that source code is generated with the help of xmls, so that we can modify it easily. (Template.xml). So this option enables you to do the changes as per your need e.g. Changing namespace or any naming convention.

    Tool generates two objects, one is interface and another is its implementing class. Suppose, your table name is User, then it generate objects i.e. classes and interface with name IUserRepositry and UserRepository. Also, it generate CRUD functions as GetUsers, GetUserById, InsertUser, DeleteUser and UpdateUser. If you want any changes in these emails, you may change corresponding template (interface/ repository), highlighted below with yellow color.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Legalxgen.Entity.DataAccess;

namespace Legalxgen.DataAccess.Repository
!cur_brak_op#
    public interface I{0}Repository
    !cur_brak_op#
      IEnumerable<{0}> Get{0}s();
      {0} Get{0}ByID(int {1}Id);
      void Insert{0}({0} {1});
      void Delete{0}(int {1}Id);
      void Update{0}({0} {1});
      void Save();
    !cur_brak_cl#
!cur_brak_cl#

Points of Interest

On the development point of view its pretty straight forward, but on the usage side its quite waste, it reduces your effort to create these interfaces and classes.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)