I can implement Factory pattern on DATA ACCESS?

Thread is closed for posting
2 posts, 0 answers
  1. Edgar F
    Edgar F avatar
    7 posts
    Member since:
    May 2014

    Posted 24 Jun 2014 Link to this post

    I have 15 tables in a database, are catalogs and follow the same structure:


    Should be separated, however I wonder if it's possible to create a generic class that stores in each according to the name of the catalog:

    something like

    DalCatalogoGenerico.SelectAll (CatalogName type);
          using (....

      return from items in db.Table ("CatalogName")

    DalCatalogoGenerico.InsertOrUpdate (BoCatalogItem item, CatalogType type);
  2. Kaloyan Nikolov
    Kaloyan Nikolov avatar
    118 posts

    Posted 26 Jun 2014 Link to this post

    Hi Edgar,

    You can use the Telerik Data Access Services Wizard to generate one plain WCF service. It will generate a repository pattern implementation as well and you can have a look how it works and how it is used. 

    In short it generates code like this:
    public partial class Repository<TEntity> : IRepository<TEntity>
            where TEntity : class
        protected IUnitOfWork unitOfWork;
        public Repository(IUnitOfWork unitOfWork)
            this.unitOfWork = unitOfWork;
        public void Add(TEntity entity)
        public void Remove(TEntity entity)
        public IQueryable<TEntity> GetAll()
            return this.unitOfWork.GetAll<TEntity>();
        public TEntity Get(ObjectKey objectKey)
            return this.unitOfWork.GetObjectByKey<TEntity>(objectKey);
        public IQueryable<TEntity> Find(Expression<Func<TEntity, bool>> predicate)
            return this.unitOfWork.GetAll<TEntity>().Where(predicate);

    Then you can inherit the class above with the proper generic argument and this will give the basic CRUD operation out of the box. If you need some custom implementations for a particular entity it should go in the derived repository class. 

    I hope this helps. 

    Kaloyan Nikolov
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
Back to Top