我想转换可以通过LINQ转换为SQL的真实表达式 从DTO表达式到实体表达式。 试图构建表达式,使用DTO实体映射器调用表达式,但表达式(逻辑上)未转换为SQL
// Function that contains the converter
public List<EngagementTypeModel> Filter(Expression<Func<EngagementTypeModel, bool>> filter) {
var body = filter.Body;
var Parameter = filter.Parameters[0];
// Model is the DTO
// NOT this ..
// Expression<Func<EngagementTypeEntity,bool>> ConvertedExpression = (EngagementTypeEntity e) => filter.Compile()(BindEntityToModel(e));
// Something like this
var ConvertedExpression1 = Expression.Lambda<Func<EngagementTypeEntity, bool>>(filter, Expression.Parameter(typeof(EngagementTypeEntity), Parameter.Name));
return _context.EngagementTypeEntities.Where(ConvertedExpression1).Select(x=>BindEntityToModel(x)).ToList();
}
// API
[HttpPost]
public ActionResult<string> SomeBusinessFilter()
{
_engagementTypeService.Filter(x => x.EngagementType == "foo" && x.Time < DateTime.Now && x.EngagementModel.EngaementTypeID == Guid.Empty);
return Json(Ok("Hey"));
}
``