gimpy gimpy - 17 days ago 7
C# Question

Resource not found for segment 'Property'

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

Answer

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.