如何在表达式>中动态更改“T in”类型
本文关键字:类型 动态 in bool 表达式 Func | 更新日期: 2024-10-25 12:13:36
我需要在域模型和视图模型之间映射实体。我在 DAL 中有存储库,在 BLL 中有服务。我正在使用自动映射器。
T Get(Expression<Func<T, bool>> predicate);
达尔
public class TEntity
{
public int Id { get; set; }
}
public class Person : TEntity
{
public string Name { get; set; }
public int Age { get; set; }
}
嘶嘶
public class TEntity
{
public int Id { get; set; }
}
public class Person : TEntity
{
public string Name { get; set; }
public int Age { get; set; }
public string Info
=> $"{this.Name}, {this.Age} years old.";
}
服务业
// Business is BLL.TEntity
public Business Get(Expression<Func<Business, bool>> predicate)
{
Expression<Func<Domain, bool>> newPredicate = predicate; // ??
var businessEntity = this.mapper.Map<Business>(
this.repository.Get(newPredicate));
return businessEntity;
}
问题是:如何从 BLL 更改 Expression> 中的内部"T in"类型。模特·模特?
简而言之:你不能。
我会将所有实体类型重构为一个单独的程序集,DAL 和 BLL 都可以引用该程序集。