如何转换PropertyInfo
为可用于调用StructuralTypeConfiguration<TStructuralType>.Ignore<TProperty>(Expression<Func<TStructuralType, TProperty>> propertyExpression)
方法的属性表达式?
我尝试使用Expression.Property()
来构造表达式,但是当我将此表达式用作propertyExpression
参数时出现以下错误:
The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.
这个错误可能是指TProperty
类型参数,我不知道如何指定只有PropertyInfo
.
我这样做是为了:使用实体框架的 StructuralTypeConfiguration.Ignore() 忽略所有属性,但指定 set。
更新
不工作的代码:
var propertyInfo = typeof(Foo).GetProperties()[0];
var expression = Expression.Default(typeof(Foo));
var expressionProperty = Expression.Property(expression, propertyInfo);
Ignore(expressionProperty);