Unable to return custom class from WCF Data Service
Asked Answered
T

1

6

I am trying to return a custom class from my WCF data service. My custom class is:

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

My data service looks like:

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();
}

However when I run the service, it gives me an error:

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()'

The same query runs perfectly fine in LINQPad.

Tautomer answered 3/10, 2010 at 18:56 Comment(2)
Renamed to WCF Data Services a year ago....Azarcon
Does using WCF Data Services with VS 2010 and ADO.Net Data Services with VS 2008 SP1 makes a difference?Tautomer
V
2

Refer to the below blog. It explains this scenario and a possible solution in detail: http://samuelmueller.com/2009/11/working-with-projections-and-dtos-in-wcf-data-services/

Vanpelt answered 28/9, 2011 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.