locked
Reflection provider Int64 entity key? RRS feed

  • Question

  • I Hope I'm doing something stupid or that there's a work around for this, couldn't see anything when searching though...  Below is my situation simplified...

    I have a POCO defined like so.

    [DataServiceKey("ContactId")]
    public class Contact
    {
    	public Int64 ContactId { get; set; }
    	public String FirstName { get; set; }
    	public String LastName { get; set; }
    	public String EmailAddress { get; set; }
    	public String Landline { get; set; }
    	public String Mobile { get; set; }
    }

    I have a WCF Data Service defined like so.

    public class TestService : DataService<TestServiceData>
    {
    	// This method is called only once to initialize service-wide policies.
    	public static void InitializeService(DataServiceConfiguration config)
    	{
    		config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
    		config.DataServiceBehavior.MaxProtocolVersion =
    			DataServiceProtocolVersion.V2;
    	}
    }

    And finally an entity container class like this.

    public class TestServiceData
    {
    	private static IList<Contact> contacts;
    	public IQueryable<Contact> Contacts { get { return contacts.AsQueryable(); } }
    	static TestServiceData()
    	{
    		contacts = new Contact[] {
    			new Contact()
    			{
    				ContactId = 1,
    				EmailAddress = "Email",
    				FirstName = "First",
    				Landline = "Landline",
    				LastName = "last",
    				Mobile = "mob"
    			}};
    	}
    }

    Note that Contact.ContactId is of type Int64.  Running http://localhost:21744/TestService.svc/Contacts/ works fine, but running http://localhost:21744/TestService.svc/Contacts(1) fails. DataService.HandleException says "System.Data.Services.DataServiceException: Bad Request - Error in query syntax."

    Change Contact.ContactId to type Int32 and this works fine, unfortunately that doesn't suit the legacy database I need this service to run against.

    So world, any ideas?  If someone else can repro this and confirm it's not behaving as expected I'll file a bug report on the connect site.

    • Edited by Ben-White Wednesday, April 4, 2012 10:22 PM not a bug
    Tuesday, April 3, 2012 7:19 PM

Answers

  • Why you tried running Contacts, did you check and see what the uri of the individual entry is in the payload? My guess would be the following:

    http://localhost:21744/TestService.svc/Contacts(1L)

    Hope this works for you.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Ben-White Wednesday, April 4, 2012 10:23 PM
    Wednesday, April 4, 2012 8:59 PM
    Moderator

All replies

  • Why you tried running Contacts, did you check and see what the uri of the individual entry is in the payload? My guess would be the following:

    http://localhost:21744/TestService.svc/Contacts(1L)

    Hope this works for you.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Ben-White Wednesday, April 4, 2012 10:23 PM
    Wednesday, April 4, 2012 8:59 PM
    Moderator
  • Many Thanks Pratik.

    Looks like I hadn't done enough reading about OData.

    Wednesday, April 4, 2012 10:24 PM