Created
January 31, 2017 01:10
-
-
Save TylerCarlson1/ddbbe07647d6aa2dda71061b0bbbb297 to your computer and use it in GitHub Desktop.
Example
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using AutoMapper; | |
namespace MapTests | |
{ | |
public class Program | |
{ | |
private static IMapper mapper = | |
new MapperConfiguration(cfg => cfg.CreateMap<application_class, domain_class>().ReverseMap()).CreateMapper(); | |
static void Main(string[] args) | |
{ | |
var i_config_application_service = new i_config_application_service(); | |
var configs = i_config_application_service.list(x => x.dt_created_at >= DateTime.Now.Date, | |
y => y.OrderBy(z => z.dt_created_at)); | |
} | |
public class domain_service_base | |
{ | |
public List<t_model> list(Expression<Func<domain_class, bool>> ef_where, | |
Func<IQueryable<domain_class>, IOrderedQueryable<domain_class>> ef_orderby) | |
{ | |
var dbSet = new List<domain_class>().AsQueryable(); | |
return ef_orderby(dbSet.Where(ef_where)).Select(c => c.t_model).ToList(); | |
} | |
} | |
public class application_class | |
{ | |
public t_model t_model { get; set; } | |
public DateTime dt_created_at { get; set; } | |
} | |
public class domain_class | |
{ | |
public t_model t_model { get; set; } | |
public DateTime dt_created_at { get; set; } | |
} | |
public class t_model | |
{ | |
} | |
public class i_config_application_service | |
{ | |
public virtual List<t_model> list(Expression<Func<application_class, bool>> ef_where, | |
Expression<Func<IQueryable<application_class>, IOrderedQueryable<application_class>>> ef_orderby) | |
{ | |
var domain_where = mapper.Map<Expression<Func<domain_class, bool>>>(ef_where); | |
var domain_orderby = | |
mapper.Map<Expression<Func<IQueryable<domain_class>, IOrderedQueryable<domain_class>>>>(ef_orderby); | |
return new domain_service_base().list(domain_where, domain_orderby.Compile()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment