Created
September 28, 2014 07:55
-
-
Save ahmad2x4/63b6c37597c105bfccbe to your computer and use it in GitHub Desktop.
Blog Automapper Expression 6
This file contains 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 class SourceRepositorySql : IRepository<Source, Destination>, IDisposable | |
{ | |
private readonly MyContext _context; | |
public SourceRepositorySql(MyContext context) | |
{ | |
_context = context; | |
} | |
public void Add(Source source) | |
{ | |
_context.Users.Add(Mapper.Map<Destination>(source)); | |
} | |
public IQueryable<Destination> Find(Expression<Func<Source, bool>> predicate) | |
{ | |
Expression<Func<Destination, Source>> mapper = Mapper.Engine.CreateMapExpression<Destination, Source>(); | |
Expression<Func<Destination, bool>> mappedSelector = predicate.Compose(mapper); | |
return _context.Users.Where(mappedSelector); | |
} | |
private bool _disposed; | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (!_disposed) | |
{ | |
if (disposing) | |
{ | |
_context.Dispose(); | |
} | |
} | |
_disposed = true; | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment