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 回答