我有以下MethodCallExpression:
{Party.Any(party => party.Address.Any(address => address.Line1.Contains("Address 1")))}
我需要将其附加到父级“属性/参数”,以便最终的lambda看起来像:
{txliferequest => txliferequest.OLifE.Party.Any(party => party.Address.Any(address => address.Line1.Contains("Address 1")))}
原始的MethodCallExpression被传递到扩展方法中,因此我尝试附加最终的lambda结构。
TXLifeRequest
public partial class TXLifeRequest : BaseEntity
{
public virtual OLifE OLifE { get; set; }
...
}
OLifE
public partial class OLifE : BaseEntity
{
public virtual List<Party> Party { get; set; }
...
}
聚会
public class Party: BaseEntity
{
public virtual List<Address> Address { get; set; }
...
}
我尝试附加的是作为属性访问器,但不确定如何执行此操作。这是我要尝试的:
//{Name = "OLifE" FullName = "IMSParamed.Entities.OLifE"}
Type parentBaseType = parentPropInfo.GetListBaseType();
//{IMSParamed.Entities.OLifE OLifE}
PropertyInfo propInfo = parentBaseType.GetParentMappedPropertyInfo();
//{OLifE}
ParameterExpression parentTypeParam2 = parentPropInfo.Name.ToParameter(parentBaseType);
//{OLifE.Party}
MemberExpression typeProp = type.Name.ToProperty(parentTypeParam2);
//Type lambdaType = typeof(Func<,>).MakeGenericType(type, typeof(bool));
MethodInfo anyMethod = ExpressionBuilder.anyTSource.MakeGenericMethod(type);
//{OLifE.Party.Any(party => party.Address.Any(address => address.Line1.Contains("Address 1")))}
MethodCallExpression any = Expression.Call(anyMethod, typeProp, methodCallExp);