示例#1
0
        public ClassA Get(string key)
        {
            key = key.Trim('\'');
            var item = TestRepo.GetAs().FirstOrDefault(a => key.Equals(a.Name));

            return(item);
        }
示例#2
0
        public EdmEntityObjectCollection Get()
        {
            var props = Request.ODataProperties();

            var model = Request.GetModel();

            var es = (EntitySetSegment)props.Path.Segments[0];

            var entityType     = es.EntitySet.EntityType();
            var collectionType = new EdmCollectionType(new EdmEntityTypeReference(entityType, false));

            var queryContext = new ODataQueryContext(model, entityType, props.Path);
            var queryOptions = new ODataQueryOptions(queryContext, Request);

            int n;

            n =
                int.TryParse(
                    Request.GetQueryNameValuePairs().Where(kv => kv.Key == "n").Select(kv => kv.Value).FirstOrDefault(), out n)
                    ? n
                    : 10;

            var @as = TestRepo.GetAs(n);

            if (queryOptions.SelectExpand != null)
            {
                props.SelectExpandClause = queryOptions.SelectExpand.SelectExpandClause;
            }

            return(new EdmEntityObjectCollection(new EdmCollectionTypeReference(collectionType), @as.Select(a => Map(model, a)).ToArray()));
        }
示例#3
0
        public IEnumerable <ClassA> Get()
        {
            int n;

            n =
                int.TryParse(
                    Request.GetQueryNameValuePairs().Where(kv => kv.Key == "n").Select(kv => kv.Value).FirstOrDefault(), out n)
                    ? n
                    : 10;
            return(TestRepo.GetAs(n));
        }
示例#4
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            config.MapODataServiceRoute(
                routeName: "OData",
                routePrefix: null,
                model: TestRepo.GetModel());

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }