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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top