Làm thế nào để chuyển đổi PropertyInfo
thành biểu thức thuộc tính có thể được sử dụng để gọi phương thức StructuralTypeConfiguration<TStructuralType>.Ignore<TProperty>(Expression<Func<TStructuralType, TProperty>> propertyExpression)
?Làm thế nào để chuyển đổi PropertyInfo thành biểu thức thuộc tính và sử dụng nó để gọi phương thức chung?
Tôi cố gắng để sử dụng Expression.Property()
để xây dựng biểu nhưng tôi nhận được lỗi sau khi tôi sử dụng biểu thức này như propertyExpression
tham số:
The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.
Lỗi này có thể đề cập đến TProperty
loại tham số mà tôi không biết cách chỉ định chỉ có PropertyInfo
.
Tôi đang thực hiện việc này liên quan đến: Use Entity Framework's StructuralTypeConfiguration.Ignore() to Ignore all properties but specified set.
CẬP NHẬT
Mã mà không hoạt động:
var propertyInfo = typeof(Foo).GetProperties()[0];
var expression = Expression.Default(typeof(Foo));
var expressionProperty = Expression.Property(expression, propertyInfo);
Ignore(expressionProperty);
Bạn nên hiển thị mã không hoạt động ... –
@JonSkeet - đã thêm. – Pol