Created
May 27, 2019 18:00
-
-
Save gashupl/dc15de55e6c39f7ca7f07444023b9c71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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