1

Closed

Self link doesn't support guid or other special types as primary key

description

If user uses guid property as primary key, the generated self link looks like:
http://localhost:9001/GuidPrimaryKeyType(guid'1a2398cd-32e9-46f1-b702-3c671ceb8f6d') However, we don't have correct model binding to parse the guid'1a2398cd-32e9-46f1-b702-3c671ceb8f6d' as Guid clr type. So the server will report an error when parsing it.

The issue doesn't only apply for Guid. It applies to any other types other than integer.

For string primary key, model binding will include single quote in id parameter. A workaround is to add an additional route:
configuration.Routes.MapHttpRoute("GetByStringId", "{controller}('{id}')");

The same issue should apply for datetime, long, decimal, double, float as well.

Since GUID, long and string are very common as primary key, I think this issue having high impact.
Closed Oct 17, 2012 at 11:07 PM by hongyes
Verified in latest build