我使用Expression Tree Serializer发送Expression< FuncDTO,布尔>>到WCF服务和
我的存储库正在使用域类型。我想将此表达式应用于我的存储库
Expression<Func<UserDto,bool>> expression = new ExpressionSerializer().Deserialize<Func<UserDto, bool>>(xmlElement);
var addressBookEntries = addressBooksRepository.Where(expression); //accepts Expression<Func<UserDomain,bool>>
如何解决此问题?
答案 0 :(得分:0)
我使用了动态linq它解决了我的问题,只有少量问题属性名称必须等于。我将动态linq转换为字符串并将其发送到wcf服务并将其用作字符串
using System.Linq;
using System.Linq.Dynamic;
public ICollection<UserDto> GetUsersByFilter(string filter)
{
var addressBooksRepository = new AddressBooksRepository();
var addressBookEntries = addressBooksRepository.GetAll().Where(filter);
//return data
}
答案 1 :(得分:-1)
尝试使用基于现有类型的类型参数创建新表达式。
public class UserDto : UserDomain
{ }
public class UserDomain
{ }
void YourMethod()
{
Expression<Func<UserDto, bool>> expression = new ExpressionSerializer().Deserialize<Func<UserDto, bool>>(xmlElement);
Func<UserDto, bool> func = expression.Compile();
Expression<Func<UserDomain, bool>> newExpression = x => func(x as UserDto);
var addressBookEntries = addressBooksRepository.Where(newExpression);
}