Dynamic LINQ: Comparing Nested Data With Parent Property

c#-4.0 dynamic-linq expression lambda linq

Question

I teach a class that is structured as follows:

 public class BestWayContext
{
    public Preference Preference { get; set; }
    public DateTime DueDate { get; set; }
    public List<ServiceRate> ServiceRate { get; set; }
}

public class ServiceRate
{
    public int Id { get; set; }
    public string Carrier { get; set; }
    public string Service { get; set; }
    public decimal Rate { get; set; }
    public DateTime DeliveryDate { get; set; }
}

Moreover, I have a dynamic Linq expression string.

"ServiceRate!= null && Preference. Either (Carrier == Preference.Carrier)"

and I want to translate the aforementioned string into Dynamic LINQ like follows:

  var expression = System.Linq.Dynamic.DynamicExpression.ParseLambda<BestWayContext, bool>(condition, null).Compile();

But it displays the following error:

enter image description here

Please tell me what I'm doing incorrectly.

1
3
1/1/2015 8:54:18 AM

Popular Answer

You wish to utilize Preference, which is a BestWayContext property, but you didn't inform the compiler. If I use Linq to create your expression, I'll perform the following:

Best Way Context List If f, then f.Preference!= null and f.ServiceRate. Where(f.Preference.Carrier == g.Carrier);

As you can see, I stated the BestWayContext Preference should be used.

0
1/1/2015 9:58:06 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