を使用した場合のエンティティにLINQでサポートされていませんタイプのメンバー「年齢は」我々は常に我々のアプリケーションでこのようなデータを選択しODataQueryOptions
public class DummyDto {
public int Id {get;set;}
public string Name {get;set;}
public int Age {get;set;}
}
とすぐに我々はページングを実装するために
ODataQueryOptions
を使用して、これはエラーになり
:
The specified type member "Age" is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
"Age"はDummyDtoのもう1つのプロパティで、上のコードでは選択していません。
我々はこのようにページングを実装:
public PageResult<DummyDto> GetAll(ODataQueryOptions<DummyDto> queryOptions) {
var result = queryOptions.applyTo(
myDummyService.getAll().Where(x => x.Id > 1000).Select(x => new DummyDto() {
Id = x.Id,
Name = x.Name
})
});
return new PageResult<DummyDto>(results as IEnumerable<DummyDto>);
我々はこれにクエリを変更したい場合は、エラーが表示されなくなります。
public PageResult<DummyDto> GetAll(ODataQueryOptions<DummyDto> queryOptions) {
var result = queryOptions.applyTo(
myDummyService.getAll().Where(x => x.Id > 1000).Select(x => new DummyDto() {
Id = x.Id,
Name = x.Name,
Age = null // simply set the property to null, because we don't want/need it in this case
})
});
誰でも何らかの理由がありますか?
のようなあなたのプロパティを宣言しますか? –
DummyDtoの定義が追加されました。 3つのプロパティ(またはそれ以上)を持っていますが、2つだけ必要です。 –
intを使用しますか?年齢とIDを定義して、null値が許容されるようにします。 – jdweng