Resource not found for segment 'Property'
Asked Answered
T

3

15

When using ADO.Net Data Services client to refresh an entity by calling the LoadProperty:

ctx.BeginLoadProperty(this, "Owner", (IAsyncResult ar) => ...

It throws an error on the server if the property is null

Error: Exception Thrown: System.Data.Services.DataServiceException: Resource not found for the segment 'Owner'. at System.Data.Services.RequestDescription.GetSingleResultFromEnumerable(SegmentInfo segmentInfo) at System.Data.Services.DataService1.CompareETagAndWriteResponse(RequestDescription description, ContentFormat responseFormat, IDataService dataService)
at System.Data.Services.DataService1.SerializeResponseBody(RequestDescription description, IDataService dataService) at System.Data.Services.DataService1.HandleNonBatchRequest(RequestDescription description) at System.Data.Services.DataService`1.HandleRequest()

Problem is that the client does not know whether the property is null or just hasn't been populated yet. The property Owner is a link from a Vehicle to a Customer.

Any ideas what's wrong?

Thanks

Trinetta answered 3/2, 2009 at 1:45 Comment(0)
P
20

Querying on primary keys generate an exception when the key does not exist. The workaround is to add a dummy true expression in the condition (eg : 1==1 && item.Id == XXX).

Without the dummy expression the ADO.NET request is:

http: //localhost//test.svc/Role(XXX)

With the dummy condition, the request is:

http: //localhost//test.svc/Role()?$filter=true and (Id eq 1)

The expected behaviour (null returned) is correct in the second case.

Pudendas answered 6/12, 2009 at 15:24 Comment(1)
This other answer is a better option. Makes for more readable code.Corporate
C
33

Set IgnoreResourceNotFoundException property of the service context to true:

svc.IgnoreResourceNotFoundException = true;
Compo answered 13/5, 2011 at 5:50 Comment(1)
Note that this property was added in .NET 3.5 SP1.Corporate
P
20

Querying on primary keys generate an exception when the key does not exist. The workaround is to add a dummy true expression in the condition (eg : 1==1 && item.Id == XXX).

Without the dummy expression the ADO.NET request is:

http: //localhost//test.svc/Role(XXX)

With the dummy condition, the request is:

http: //localhost//test.svc/Role()?$filter=true and (Id eq 1)

The expected behaviour (null returned) is correct in the second case.

Pudendas answered 6/12, 2009 at 15:24 Comment(1)
This other answer is a better option. Makes for more readable code.Corporate
W
3

I've received a "Resource not found for segment 'Property'" error also. Mine appears to be that in the where clause I am looking by primary key. I have found some resources that say it will throw an error (even when using FirstOrDefault()) when using a primary key that doesn't exist (as opposed to other where clauses that just do not provide results). I'd guess a similar thing is happening to yourself.

Wellestablished answered 10/2, 2009 at 4:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.