0

LINQPad を試して、LINQ を使用して Netflix OData をクエリします。特定の俳優が出演するすべての映画を検索しようとしています。例:

from t in Titles 
from p in t.Cast
where p.Name == "Morgan Freeman"
select t.Name

これにより、次の結果が得られます。

NotSupportedException: 変換中のクエリの最後のエンティティ タイプのみを投影できます

私も試しました:

from p in People
from t in p.TitlesActedIn
where p.Name == "Morgan Freeman"
select t.Name

次のエラーが発生します。

NotSupportedException: メソッド 'Select' はサポートされていません

where句でIDを使用したり、別のものを選択したりするなど、他のいくつかのアプローチを試しましたが、どこにも行きませんでした。

4

1 に答える 1

1

You can do either this:

from p in People
where p.Id == 190
from t in p.TitlesActedIn
select new { Name = t.Name }

But note that this requires you not specify the Id, this translates to: /People(190)/TitlesActedIn?$select=Name

If you need to filter based on non-key properties, you need to do something like:

from p in People
where p.Name == "Morgan Freeman"
select new Person {
    TitlesActedIn = p.TitlesActedIn
}

This translates to: /People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn

You could also just ask for the names of those titles, but LinqPad doesn't seem to have a way to do that, due to the type of properties it generates. It would look like:

from p in People
where p.Name == "Morgan Freeman"
select new Person {
    TitlesActedIn = p.TitlesActedIn.Select(t => new Title { Name = t.Name })
}

Which would translate to: /People?$filter=Name eq 'Morgan Freeman'&$expand=TitlesActedIn&$select=TitlesActedIn/Name

Thanks, Vitek Karas [MSFT]

于 2010-06-10T16:42:07.190 に答える