Ash*_*ish 6 c# return-type service-operations wcf-data-services
我试图从我的WCF数据服务返回一个自定义类.我的自定义类是:
[DataServiceKey("ID")]
public class Applist {
public int ID { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的数据服务看起来像:
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();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行该服务时,它给了我一个错误:
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()'
Run Code Online (Sandbox Code Playgroud)
在LINQPad中,相同的查询运行完全正常.
请参考下面的博客。它详细解释了这种情况和可能的解决方案: http://samuelmueller.com/2009/11/working-with-projections-and-dtos-in-wcf-data-services/
| 归档时间: |
|
| 查看次数: |
5434 次 |
| 最近记录: |