【发布时间】:2017-09-18 01:22:51
【问题描述】:
我们有以下实体:
public class Employee
{
public int Serial { get; set; }
public string FullName { get; set; }
public Section Section { get; set; }
}
public class Section
{
public int Serial { get; set; }
public string SectionName { get; set; }
public SupperSection SupperSection { get; set; }
public ICollection<Employee> Sections { get; set; }
}
我们想从以下字符串创建一个MemberExpression:
Employee.Section.SectionName
我们这样做:
// selectorString = Section.SectionName
// we wanna create entity => entity.Section.SectionName
ParameterExpression parameterExpression = Expression.Parameter(entityType, "entity");
MemberExpression result = Expression.Property(parameterExpression, selectorString); // Exception
但它会引发以下异常:
“System.ArgumentException”类型的未处理异常发生在 System.Core.dll
附加信息:没有为类型“DtoContainer.Employee”定义属性“System.String SectionName”
我们该怎么做?
【问题讨论】:
标签: c# linq expression