0

假设我有一个查询,它选择一个定义的类型,如下所示:

public class SomeObject
{
     public DateTime CreatedDate { get; set; }
}

private class MyType
{
    internal SomeObject Object1 { get; set; }
    internal SomeThing Object2 { get; set; }
    internal DateTime SomeDate { get; set; }   
}

var query =  from bla in context.Melp join ..... 
             select new MyType()
             {
                  Object1 = something,
                  Object2 = somethingelse,
                  SomeDate = bla.date
             }

现在我们 DynamicLinq 在结果集上添加动态的、用户定义的排序,如下所示:

query.OrderBy("SomeDate"); 

或者

query.OrderBy("Object1.CreatedDate");

但是当我尝试订购时,例如,“SomeDate”或“Object1.CreatedDate”,我收到提示异常:

“MyType”类型中不存在属性或字段“SomeDate”

现在,当我只是将方法语法中的排序添加到查询中时:

query = query.OrderBy(x => x.SomeDate)

或者

query = query.OrderBy(x => x.Object1.CreatedDate)

一切正常,所以我认为这可能是 DynamicLinq 中的一个错误,或者我说错了......

有任何想法吗?

4

1 回答 1

3

Dynamic Linq makes heavy use of Reflection. Maybe it is a problem because your properties are marked as internal and the method <Type>.GetProperty method (which will be used by the Dynamic Linq library) will not watch for internal properties unless the BindingFlags would be adapted.

Give it a try to mark them public and your class also.

于 2013-04-16T08:30:41.983 回答