我试图用 防爆pression.Property()
建设前pression,但我得到的时候我用这个EX pression为 propertyEx pression 参数:
的方法的类型参数不能从使用推断。请尝试显式指定类型参数。
此错误可能是指 TProperty
键入参数,我不知道如何指定只具有的PropertyInfo
。
我做这涉及到:Use实体框架的StructuralTypeConfiguration.Ignore()忽略所有属性,但指定的一组。
更新
code这是不工作:
VAR的PropertyInfo = typeof运算(富).GetProperties()[0];
VAR EX pression =前pression.Default(typeof运算(富));
VAR EX pressionProperty =前pression.Property(如pression,的PropertyInfo);
忽略(如pressionProperty);
解决方案
VAR参数=前pression.Parameter(的EntityType,实体);
VAR属性=前pression.Property(参数的PropertyInfo);
VAR funcType = typeof运算(Func键<,>)MakeGenericType(的EntityType,propertyInfo.PropertyType)。
VAR的λ=前pression.Lambda(funcType,财产,参数);
structureConfiguration.GetType()
.GetMethod(忽略)
.MakeGenericMethod(propertyInfo.PropertyType)
.Invoke(structureConfiguration,新的[] {拉姆达});
How to convert PropertyInfo
to property expression which can be used to invoke StructuralTypeConfiguration<TStructuralType>.Ignore<TProperty>(Expression<Func<TStructuralType, TProperty>> propertyExpression)
method?
I tried to use Expression.Property()
to construct expression but I am getting following error when I use this expression as propertyExpression
parameter:
The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly.
This error probably refers to TProperty
type parameter which I don't know how to specify having only PropertyInfo
.
I am doing this in relation to: Use Entity Framework's StructuralTypeConfiguration.Ignore() to Ignore all properties but specified set.
UPDATE
Code which is not working:
var propertyInfo = typeof(Foo).GetProperties()[0];
var expression = Expression.Default(typeof(Foo));
var expressionProperty = Expression.Property(expression, propertyInfo);
Ignore(expressionProperty);
解决方案
var parameter = Expression.Parameter(entityType, "entity");
var property = Expression.Property(parameter, propertyInfo);
var funcType = typeof(Func<,>).MakeGenericType(entityType, propertyInfo.PropertyType);
var lambda = Expression.Lambda(funcType, property, parameter);
structureConfiguration.GetType()
.GetMethod("Ignore")
.MakeGenericMethod(propertyInfo.PropertyType)
.Invoke(structureConfiguration, new[]{lambda});
相关推荐
最新文章