Entity Framework없이 Microsoft OData 구현을 사용할 수 있습니다. 필요한 것은 IQueryable
의 구현입니다. 다음은 객체 배열을 쿼리하는 예제 OData 서비스입니다.
using System.Web.Http;
using System.Web.Http.OData;
using System.Web.Http.OData.Builder;
using System.Web.Http.OData.Query;
// GET api/values
[ActionName("FromList")]
public IList<Poco> GetFromList(ODataQueryOptions<Poco> queryOptions)
{
IQueryable<Poco> data = (
new Poco[] {
new Poco() { id = 1, name = "one", type = "a" },
new Poco() { id = 2, name = "two", type = "b" },
new Poco() { id = 3, name = "three", type = "c" }
})
.AsQueryable();
var t = new ODataValidationSettings() { MaxTop = 25 };
queryOptions.Validate(t);
var s = new ODataQuerySettings() { PageSize = 25 };
IEnumerable<Poco> results =
(IEnumerable<Poco>)queryOptions.ApplyTo(data, s);
return results.ToList();
}
public class Poco
{
public int id { get; set; }
public string name { get; set; }
public string type { get; set; }
}
이 방법을 사용하면 데이터베이스에서 필터하는 기능을 잃지 않고 대신 메모리에서 수행 할 수 있습니다. 어쨌든 우아한 둥근, IQueryable 인터페이스를 다시 구현하지 않고? – gdp
@gdp [Simple.OData] (http://www.codeproject.com/Articles/686240/reasons-to-consume-OData-feeds-using-Simple-ODa)와 같은 것을 찾고 계십니까? – qujck
내가 보일 것이다,하지만 이상적으로 내가 OData 쿼리를 구문 분석하고 내가 SQL을 동적으로 구축 할 수있는 일종의 모델로 변환하려고합니다. 임 메신저 프로젝트의 데이터 계층에는 IQueryable을 반환 할 수있는 기능이 없으며 여전히 페이징/필터링이 DB에서 수행되기를 원합니다. – gdp