Parent Navigation Property C# Expression Tree Parameter

c# entity-framework expression-trees lambda

Question

How can I make a ParameterExpression for a 1 to * Navigation Property's parent side?

For the child entity, the following functions:

var parameter = Expression.Parameter(
    typeof(T), // where T is the entity type
    GetParameterName()); // helper method to get alias

Similar attempts on TParent result in a query coming from the Context rather than a property on the child.

The equivalent in lambda would look like this:

var q = from f in context.Foo 
        where f.Bar.BarId == 1...
         // where bar is the Navigation Property to the parent

Edit for precision:

I use the next to turn a property into a member expression:

Expression exp = Expression.Equal(
    Expression.Property(parameter, "SomeColumn"),
    Expression.Constant("SomeValue"));

It seems that in this instance, MemberExpression should be used instead of ParameterExpression.

1
1
2/11/2009 3:38:49 PM

Expert Answer

I'm not really sure... Zzz-5-Zzz a ".Bar"ParameterExpression - it is aMemberExpression . f the argument is. What specifically do you want to do?

One way is to load the example code into Reflector, disable the.NET 3.5 hints, and study how it operates; this will result in code that resembles here but is often simple to understand.

1
2/11/2009 3:27:08 PM


Related Questions





Related

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