Skip to content

Instantly share code, notes, and snippets.

@dfch

dfch/00-README.md

Last active Feb 27, 2016
Embed
What would you like to do?
ODataQueryOptions do not apply $filter and $orderby options to IQueryable when using EntityFramework 6 with SQL Server
public class Node : BaseEntity
{
public long? EntityId { get; set; }
[Required]
public string Parameters { get; set; }
[Required]
public long EntityKindId { get; set; }
[JsonIgnore]
[ForeignKey("EntityKindId")]
public virtual EntityKind EntityKind { get; set; }
[Required]
public long ParentId { get; set; }
[JsonIgnore]
[ForeignKey("ParentId")]
public virtual Node Parent { get; set; }
[JsonIgnore]
public virtual ICollection<Node> Children { get; set; }
[JsonIgnore]
[InverseProperty("Destination")]
public virtual ICollection<Assoc> IncomingAssocs { get; set; }
[JsonIgnore]
[InverseProperty("Source")]
public virtual ICollection<Assoc> OutgoingAssocs { get; set; }
}
[AppclusiveAuthorize]
[EnableQuery(PageSize = 45)]
public async Task<IHttpActionResult> GetNodes(ODataQueryOptions<Node> queryOptions)
{
Contract.Requires(null != queryOptions, "|400|");
queryOptions.Validate(_validationSettings);
return Ok<IEnumerable<Node>>(db.Nodes);
}
GET http://localhost:53422/api/Core/Nodes()?$filter=Name%20ne%20'Root%20Node'&$orderby=Modified,%20Created%20desc,%20Id%20asc&$skip=5&$top=35 HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
User-Agent: Microsoft ADO.NET Data Services
Authorization: Basic UXVlc3Rpb246d2hvLXJlYWxseS1wb3N0cy1CQVNFNjQtZW5jb2RlZC1jcmVkZW50aWFscy10by1wdWJsaWMtd2ViLXNpdGVz
Host: localhost:53422
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; odata=minimalmetadata; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
Set-Cookie: biz.dfch.CS.Appclusive.Core.Security.AuthenticationFilters.MultiAuthenticationFilter=AB-C0-4F-AC-B7-01-72-EF-57-80-74-A3-B0-E4-D6-E3-A4-4C-5A-73-79-4D-BA-64-A9-03-37-56-D4-9B-A6-4D
DataServiceVersion: 3.0
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
Date: Sat, 27 Feb 2016 13:03:28 GMT
Content-Length: 5826
{
"odata.metadata":"http://localhost:53422/api/Core/$metadata#Nodes","value":[
{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"13","Tid":"22222222-2222-2222-2222-222222222222","Name":"locally","Description":"locally is a mandrake for whiles purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:49.7239236+01:00","Modified":"2016-02-19T13:05:49.7239236+01:00","RowVersion":"AAAAAAAAjUU="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"14","Tid":"22222222-2222-2222-2222-222222222222","Name":"sneak","Description":"sneak is a pitman for stagnate purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:50.0039396+01:00","Modified":"2016-02-19T13:05:50.0039396+01:00","RowVersion":"AAAAAAAAjUs="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"15","Tid":"22222222-2222-2222-2222-222222222222","Name":"recess","Description":"recess is a oxidase for rainbow purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:50.3719606+01:00","Modified":"2016-02-19T13:05:50.3719606+01:00","RowVersion":"AAAAAAAAjVE="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"16","Tid":"22222222-2222-2222-2222-222222222222","Name":"petrosal","Description":"petrosal is a ramrod for carabao purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:50.6599771+01:00","Modified":"2016-02-19T13:05:50.6599771+01:00","RowVersion":"AAAAAAAAjVc="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"17","Tid":"22222222-2222-2222-2222-222222222222","Name":"carabao","Description":"carabao is a hindmost for caroche purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:50.9159918+01:00","Modified":"2016-02-19T13:05:50.9159918+01:00","RowVersion":"AAAAAAAAjV0="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"18","Tid":"22222222-2222-2222-2222-222222222222","Name":"still","Description":"still is a basque for mainland purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:51.2250094+01:00","Modified":"2016-02-19T13:05:51.2250094+01:00","RowVersion":"AAAAAAAAjWM="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"19","Tid":"22222222-2222-2222-2222-222222222222","Name":"vendace","Description":"vendace is a lurdan for joy purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:51.5430276+01:00","Modified":"2016-02-19T13:05:51.5430276+01:00","RowVersion":"AAAAAAAAjWk="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"20","Tid":"22222222-2222-2222-2222-222222222222","Name":"mariner","Description":"mariner is a covert for derma purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:51.8220436+01:00","Modified":"2016-02-19T13:05:51.8220436+01:00","RowVersion":"AAAAAAAAjW8="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"21","Tid":"22222222-2222-2222-2222-222222222222","Name":"terrapin","Description":"terrapin is a sporty for spicule purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:52.0860587+01:00","Modified":"2016-02-19T13:05:52.0860587+01:00","RowVersion":"AAAAAAAAjXU="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"22","Tid":"22222222-2222-2222-2222-222222222222","Name":"vitellin","Description":"vitellin is a squeeze for varices purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:52.3860758+01:00","Modified":"2016-02-19T13:05:52.3860758+01:00","RowVersion":"AAAAAAAAjXs="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"23","Tid":"22222222-2222-2222-2222-222222222222","Name":"locally","Description":"locally is a aggrade for ultra purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:52.7470965+01:00","Modified":"2016-02-19T13:05:52.7470965+01:00","RowVersion":"AAAAAAAAjYE="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"24","Tid":"22222222-2222-2222-2222-222222222222","Name":"missal","Description":"missal is a resale for vendace purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:53.0281126+01:00","Modified":"2016-02-19T13:05:53.0281126+01:00","RowVersion":"AAAAAAAAjYc="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"25","Tid":"22222222-2222-2222-2222-222222222222","Name":"matins","Description":"matins is a petrosal for swain purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:53.3061285+01:00","Modified":"2016-02-19T13:05:53.3061285+01:00","RowVersion":"AAAAAAAAjY0="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"26","Tid":"22222222-2222-2222-2222-222222222222","Name":"oxidase","Description":"oxidase is a ultra for mannish purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:53.6611488+01:00","Modified":"2016-02-19T13:05:53.6611488+01:00","RowVersion":"AAAAAAAAjZM="
},{
"EntityId":null,"Parameters":"{}","EntityKindId":"23","ParentId":"1","Id":"27","Tid":"22222222-2222-2222-2222-222222222222","Name":"leal","Description":"leal is a varices for aggrade purposes","CreatedById":"3","ModifiedById":"3","Created":"2016-02-19T13:05:53.9841672+01:00","Modified":"2016-02-19T13:05:53.9841672+01:00","RowVersion":"AAAAAAAAjZk="
}
]
,
"odata.nextLink":"http://localhost:53422/api/Core/Nodes()?$filter=Name%20ne%20%27Root%20Node%27&$orderby=Modified%2C%20Created%20desc%2C%20Id%20asc&$top=20&$skip=20"
}
2016-02-27 14:03:28,285 [9] INFO biz.dfch.CS.Utilities.Logging.LogBase [(null)] <(null)> - p__linq__0: Root Node
2016-02-27 14:03:28,286 [9] INFO biz.dfch.CS.Utilities.Logging.LogBase [(null)] <(null)> - p__linq__1: 5
2016-02-27 14:03:28,286 [9] INFO biz.dfch.CS.Utilities.Logging.LogBase [(null)] <(null)> - p__linq__2: 35
2016-02-27 14:03:28,323 [9] INFO biz.dfch.CS.Utilities.Logging.LogBase [(null)] <(null)> - Intercepted on: ReaderExecuted :- IsAsync: False, Command Text:
SELECT TOP (16)
[Limit1].[Id] AS [Id],
[Limit1].[EntityId] AS [EntityId],
[Limit1].[Parameters] AS [Parameters],
[Limit1].[EntityKindId] AS [EntityKindId],
[Limit1].[ParentId] AS [ParentId],
[Limit1].[Tid] AS [Tid],
[Limit1].[Name] AS [Name],
[Limit1].[Description] AS [Description],
[Limit1].[CreatedById] AS [CreatedById],
[Limit1].[ModifiedById] AS [ModifiedById],
[Limit1].[Created] AS [Created],
[Limit1].[Modified] AS [Modified],
[Limit1].[RowVersion] AS [RowVersion]
FROM ( SELECT [Project1].[Id] AS [Id], [Project1].[EntityId] AS [EntityId], [Project1].[Parameters] AS [Parameters], [Project1].[EntityKindId] AS [EntityKindId], [Project1].[ParentId] AS [ParentId], [Project1].[Tid] AS [Tid], [Project1].[Name] AS [Name], [Project1].[Description] AS [Description], [Project1].[CreatedById] AS [CreatedById], [Project1].[ModifiedById] AS [ModifiedById], [Project1].[Created] AS [Created], [Project1].[Modified] AS [Modified], [Project1].[RowVersion] AS [RowVersion]
FROM ( SELECT
[Extent1].[Id] AS [Id],
[Extent1].[EntityId] AS [EntityId],
[Extent1].[Parameters] AS [Parameters],
[Extent1].[EntityKindId] AS [EntityKindId],
[Extent1].[ParentId] AS [ParentId],
[Extent1].[Tid] AS [Tid],
[Extent1].[Name] AS [Name],
[Extent1].[Description] AS [Description],
[Extent1].[CreatedById] AS [CreatedById],
[Extent1].[ModifiedById] AS [ModifiedById],
[Extent1].[Created] AS [Created],
[Extent1].[Modified] AS [Modified],
[Extent1].[RowVersion] AS [RowVersion]
FROM [core].[Node] AS [Extent1]
WHERE (([Extent1].[Tid] = @DynamicFilterParam_1) OR (@DynamicFilterParam_2 IS NOT NULL)) AND (([Extent1].[Tid] = @DynamicFilterParam_3) OR (@DynamicFilterParam_4 IS NOT NULL)) AND ( NOT (([Extent1].[Name] = @p__linq__0) AND (0 = (CASE WHEN (@p__linq__0 IS NULL) THEN cast(1 as bit) ELSE cast(0 as bit) END))))
) AS [Project1]
ORDER BY [Project1].[Modified] ASC, [Project1].[Created] DESC, [Project1].[Id] ASC
OFFSET @p__linq__1 ROWS FETCH NEXT @p__linq__2 ROWS ONLY
) AS [Limit1]
ORDER BY [Limit1].[Modified] ASC, [Limit1].[Created] DESC, [Limit1].[Id] ASC
/**
* Copyright 2014-2016 d-fens GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.