6

WCF データ サービスからカスタム クラスを返そうとしています。私のカスタムクラスは次のとおりです。

[DataServiceKey("ID")]
public class Applist {
    public int ID { get; set; }
    public string Name { get; set; }
}

私のデータ サービスは次のようになります。

public static void InitializeService(IDataServiceConfiguration config)
{
    config.RegisterKnownType(typeof(Applist));
    config.SetEntitySetAccessRule("*", EntitySetRights.All);
    config.SetServiceOperationAccessRule("GetApplications", ServiceOperationRights.AllRead);
}

[WebGet]
public IQueryable<Applist> GetApplications() {
    var result = (from p in this.CurrentDataSource.Applications
          orderby p.ApplicationName
          group p by p.ApplicationName into g
          select new Applist { ID = g.Min(p => p.id), Name = g.Key });

    return result.AsQueryable();
}

ただし、サービスを実行すると、エラーが発生します。

Request Error Request Error The server encountered an error processing the request. 
The exception message is 'Unable to load metadata for return type
'System.Linq.IQueryable`1[ApplicationService.Applist]' of method
'System.Linq.IQueryable`1[ApplicationService.Applist] GetApplications()'

同じクエリが LINQPad で問題なく実行されます。

4

1 に答える 1

2

下記ブログ参照。このシナリオと考えられる解決策について詳しく説明しています: http://samuelmueller.com/2009/11/working-with-projections-and-dtos-in-wcf-data-services/

于 2011-09-28T12:16:09.387 に答える