Dynamic linq unable to parse ordering

dynamic-linq entity-framework linq

Question

Say I have a query that selects into a defined type like so:

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
             }

Now we DynamicLinq to add dynamic, user defined, sort on the result set, like so:

query.OrderBy("SomeDate"); 

or

query.OrderBy("Object1.CreatedDate");

but when I try to order on, for example, "SomeDate" or "Object1.CreatedDate", I get prompted with an exception:

No property or field 'SomeDate' exists in type 'MyType'

Now, when I just add the ordering in method syntax to the query:

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

or

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

Everything works, so I think this might be either a bug in DynamicLinq or I'm calling it wrong...

Any ideas?

1
0
4/16/2013 8:13:50 AM

Accepted Answer

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.

3
4/16/2013 8:36:12 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow