Skip to content

Instantly share code, notes, and snippets.

@hadoan
Created May 26, 2016 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadoan/2f56c0e8edb94b5786fadb675b8eb9f3 to your computer and use it in GitHub Desktop.
Save hadoan/2f56c0e8edb94b5786fadb675b8eb9f3 to your computer and use it in GitHub Desktop.
public class DataMapper<TEntity, TIDType, TLinqEntity> : IDataMapper<TEntity, TIDType, TLinqEntity>
where TEntity : AbstractBaseData<TIDType>
where TLinqEntity : EntityObject
{
public IList<TEntity> GetEntitiesFromEF(IList<TLinqEntity> linqEntities)
{
Mapper.Initialize
(
cfg =>
{
cfg.CreateMap<TLinqEntity, TEntity>();
cfg.CreateMap<TEntity, TLinqEntity>();
}
);
var listOfEntities = Mapper.Map<IList<TLinqEntity>, IList<TEntity>>(linqEntities);
return listOfEntities;
}
}
//Hàm GetAll sẽ có dạng như sau:
public virtual IList<TEntity> GetAll()
{
var entities = this.SelectAll();
var listOfEntites = Factory.CreateDataMapper<TEntity, TIDType, TLinqEntity>().GetEntitiesFromEF(entities);
return listOfEntites;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment