Reputation: 1
background:
This LINQ query in Linqpad (or in VS2010 for that matter)
EntityTypes.Where(x => x.EntityUrn == "http://foo")
translates to the following oData compliant URI:
http://localhost/OData.svc/EntityTypes('http://foo') (this is because the EntityUrn is the entity key...if my Linq query specifies any other field, the $filter syntax is used instead)
The problem is that this oData URI returns an error due to restricted characters in the Entity Key (see blogs.msdn.com/b/peter_qian/archive/2010/05/25/using-wcf-data-service-with-restricted-characrters-as-keys.aspx)
So what I want to do is have this LINQ query automatically translate to this equivalent oData compliant URI:
http://localhost/OData.svc/EntityTypes?$filter=EntityUrn eq 'http://foo'
Any suggestions how I can do this?
Upvotes: 0
Views: 578
Reputation: 13320
As already noted above, even if you work around the problem at hand the bigger problem still applies and that is that your entities are not addresable through their edit/self links. This means that you won't able to use navigation in your queries (/Customer(0)/Orders) and that your service won't able to accept any PUT/DELETE requests for its entities. So if at all possible I would change the model to not use the URL as a key property. Instead use some value which can be part of the URI path segment.
It is not directly possible to modify the URL generated by the LINQ provider, mainly because there's no public hook into the URL generation process. You could obviously write one from scratch, but that's way too much work.
Upvotes: 1