我正在尝试从我的 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 中运行得非常好。