我剛開始使用Lambda表達式,並且非常喜歡這個快捷方式。我也喜歡這個事實,即我在範圍內的範圍內包含了範圍。我遇到的一件事是嵌套lambdas。這就是我要做的:實體框架和嵌套的Lambda表達式
public void DoSomeWork()
{
MyContext context = new MyDomainContext();
context.GetDocumentTypeCount(ci.CustomerId, io =>
{
if (io.HasError)
{
// Handle error
}
// Do some work here
// ...
// make DB call to get data
EntityQuery<AppliedGlobalFilter> query =
from a in context.GetAppliedGlobalFiltersQuery()
where a.CustomerId == ci.CustomerId && a.FilterId == 1
select a;
context.Load<AppliedGlobalFilter>(query, lo =>
{
if (lo.HasError)
{
}
**// Do more work in this nested lambda.
// Get compile time error here**
}
}, null);
}, null);
}
第二拉姆達是我得到以下編譯時錯誤:
無法轉換Lambda表達式鍵入「System.ServiceModel.DomainService.Client.LoadBehavior」因爲它不是委託類型
編譯器爲Load方法選擇了錯誤的重載,即使我使用的是前一個Lambda中的相同重寫。
這是因爲我想巢?或者我還有其他錯誤?如上面我的評論描述
感謝,
斯科特
對不起 - 我發現了這個問題。它與嵌套的lambda無關,並且與我的Lambda中嚴重的格式化循環有關。它使智力發瘋,並報告一個虛假的錯誤。上面的代碼都很好。 – Scott 2010-12-10 20:32:30