Skip to content

Instantly share code, notes, and snippets.

@gashupl
Created May 27, 2019 18:00
Show Gist options
  • Save gashupl/dc15de55e6c39f7ca7f07444023b9c71 to your computer and use it in GitHub Desktop.
Save gashupl/dc15de55e6c39f7ca7f07444023b9c71 to your computer and use it in GitHub Desktop.
public abstract class RepositoryBase<T> : IRepository<T> where T : Entity
{
protected Dyn365ServiceContext ServiceContext;
protected IOrganizationService OrgService;
public RepositoryBase(IOrganizationService service)
{
this.OrgService = service;
this.ServiceContext = new Dyn365ServiceContext(service);
}
public void Create(T entity)
{
this.ServiceContext.AddObject(entity);
}
public T GetById(Guid id)
{
var entityName = typeof(T).Name;
return this.OrgService.Retrieve(entityName, id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)).ToEntity<T>();
}
public void SaveChanges()
{
this.ServiceContext.SaveChanges();
}
public void Dispose()
{
ServiceContext.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment