:ASP.NET 웹 API 된 IQueryable <T> 도전
API/{컨트롤러}/{ID}/{수집}
예 : api/customers/123/addresses
해당하는 Get 작업에서 IQueryable Of T
을 반환하고 싶습니다. 나는 이와 같은 것을 원한다 :
public IQueryable<????> GetCollection(int id, string collection)
{
switch(collection)
{
case "addresses":
return _addresses.AsQueryable();
break;
case "orders":
return _orders.AsQueryable();
break;
default:
throw new Exception(NotSupported);
}
}
이 작업을 수행 할 수 있습니까?
권장되는 접근 방법은 무엇입니까?
이러한 제안 모두 실패합니다. 두려워요. 두 경우 모두 예외가 발생합니다. –
_ 어떤 오류가 발생합니까?_ – SLaks
1) IQueryable 제공 : System.Runtime.Serialization.SerializationException : 형식 'System.Linq.EnumerableQuery'1 [[MvcApplication1.Controllers.Address, MvcApplication1, 버전 = 1.0.0.0, 문화 = 중립, PublicKeyToken = null]]' 데이터 계약 이름 'ArrayOfAddress : http : //schemas.datacontract.org/2004/07/MvcApplication1.Controllers'가 필요하지 않습니다. DataContractResolver를 사용하거나 KnownTypeAttribute 특성을 사용하거나 DataContractSerializer에 전달 된 알려진 형식 목록에 추가하여 알려진 형식 목록에 정적으로 알려지지 않은 형식을 추가하는 것이 좋습니다. –