我试图通过c#反射来填充一个一对多的关系。我尝试实现的是以下EF查询
_db.Entry(item).Collection(p => p.Valori).Query().OrderBy(o=>o.Ordinamento).Load();我的要求是使用我自己的注释自动创建查询
[EagerLoad("Ordinamento")]
[InverseProperty("Attributo")]
public virtual ICollection<AttributoValore> Valori { get; set; } 直到order by语句正常工作
_db.Entry(entity).Collection(propertyInfo.Name).Load();其中entity是包含我要填充的集合和propertyInfo.Name ==“Valori”的对象。
我找不到正确的语法来创建lamda表达式this代码
ParameterExpression pe = Expression.Parameter(type, "x");
Expression<Func<object, K>> expr = Expression.Lambda<Func<object, K>>(Expression.Property(pe, el.ordinamento), pe);
_db.Entry(entity)
.Collection<Object>(propertyInfo.Name)
.Query()
.OrderBy(expr)
.Load();生成异常: System.ArgumentException:'Jerp.AttributoValore‘类型的ParameterExpression不能用于’System.Object‘类型的委托参数。有人能帮我吗?
https://stackoverflow.com/questions/51368014
复制相似问题