0
我正在写一个通用的实体Dto Mapper,我有一个问题。我想以编程方式描述映射。C#表达式部分解析。 Curring?
public void ById(Expression<Func<TDto, object>> propertySelector, Expression<Func<TEntity, TDto, bool>> expression) {
// Just the Setter what will be mapped
}
所以在我我叫ById函数并通过所需的表达式。在这种情况下,这种映射描述了如何获取Entity.UserId等于Dto.Id的实体列表。
ById((x, y) => x.UserId.Equals(y.Id));
后端服务本身也是通用的并由“TDto”类型生成。后端服务已经包含了一个“Where”函数来加入一个函数。
public List<TEntity> Where<TEntity>(Func<TEntity, bool> predicate) {
ObjectSet<TEntity> Column = _getGenericColumnByType();
return Column.Where(predicate).ToList();
}
所以通常我会按以下方式调用我的后端。
GenericBackendService<TEntity> Service = // generateMyService;
Guid searchId = // my Guid im searching for
var result = Service.Where(x => x.Id.Equals(searchId));
现在出现了我的问题。有没有办法解决我的(x,y)=> x.UserId.Equals(y.Id)表达式的第二部分,并创建一个像这样的func对象x => x.UserId.Equals(“123 -456-678“)?
public Func<TEntity, bool> MagicFunction(Expression<Func<TEntity, TDto, bool>> expression) {
//
// in -> (x, y) => x.UserId.Equals(y.Id)
//
// Do the magic
//
// out -> x => x.UserId.Equals("The Id I resolved from y.Id")
//
return function;
}
好吧,我明白了。然后,我需要过度理解我的概念。 – 2014-12-15 11:38:47