2009-02-11 102 views
1

如何爲1到*導航屬性的父級創建ParameterExpression?用於父導航的C#表達式樹參數屬性

的子實體以下工作:

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

試穿TParent類似的東西產生的查詢源自語境,而不是對孩子的屬性。

拉姆達相當於會是這樣的:

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

爲清楚起見編輯:

我用下面的從屬性創建成員表達:

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

所以它看起來像我應該使用MemberExpression而不是ParameterExpression這種情況。

回答

1

我有點困惑...「.Bar」不是 a​​- 它是一個MemberExpressionf是參數。你想要做什麼?

請注意,一個選項是將示例代碼加載到反射器中,轉向.NET 3.5提示,並閱讀它是如何實現的 - 它看起來像代碼here,但通常很容易遵循。