This is a migrated thread and some comments may be shown as answers.

I can implement Factory pattern on DATA ACCESS?

1 Answer 23 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Edgar F
Top achievements
Rank 2
Edgar F asked on 24 Jun 2014, 05:32 PM
I have 15 tables in a database, are catalogs and follow the same structure:

id
key
Description

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);

1 Answer, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 26 Jun 2014, 11:55 AM
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)
    {
        this.unitOfWork.Add(entity);
    }
 
    public void Remove(TEntity entity)
    {
        this.unitOfWork.Delete(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. 

Regards,
Kaloyan Nikolov
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Development (API, general questions)
Asked by
Edgar F
Top achievements
Rank 2
Answers by
Kaloyan Nikolov
Telerik team
Share this question
or