locked
Azure Mobile Services Unable to retrieve [ComplexType] from .net backend RRS feed

  • Question

  • With the current Azure Mobile Services on a .NET Backend there seems to be an issue when you use a [ComplexType] property on a EntityData object.

    for example:

    public class TodoItem : EntityData
    {
        public string Text { get; set; }
    
        public bool Complete { get; set; }
    
        public ExampleComplexType Example { get; set; }
    }
    
    [ComplexType]
    public class ExampleComplexType
    {
        public string X { get; set; }
    }

    use that with the sample TodoItemController and the database gets created just fine, and data can be inserted. However the JSON returned from GetAllTodoItems() refuses to return the Example.

    Any thoughts?

    Wednesday, November 26, 2014 7:56 PM

Answers

  • I ended up using the same technique described here under "Including related entities from service" for expanding related child entities to expand complex types. The [ComplexType] annotation didn't include the type in the serialised JSON response - in fact, I'm not using this annotation at all. In my case, my Get controller action is annotated with multiple QueryableExpand annotations, one to include related child entities of the parent object and the others to include the complex type properties.

    Saturday, November 29, 2014 10:01 PM

All replies

  • I ended up using the same technique described here under "Including related entities from service" for expanding related child entities to expand complex types. The [ComplexType] annotation didn't include the type in the serialised JSON response - in fact, I'm not using this annotation at all. In my case, my Get controller action is annotated with multiple QueryableExpand annotations, one to include related child entities of the parent object and the others to include the complex type properties.

    Saturday, November 29, 2014 10:01 PM
  • Thanks for the reply but its not a solution to this issue, my database tables are having multiple 1:1 relationships which I don't want to foreign key out to a different table. The model is nicely generated with the help of the complex type and it works for insert/update/delete. The QueryableExpand method does not work here, I've tried that as well.

    Anyone else? or is it just a bug and the way to roll this, will be a custom controller? The Custom controller appears to function as expected on the objects, its just not pretty to work around something that should be in the framework.

    Monday, December 1, 2014 7:51 AM
  • There isn't another solution, unfortunately, so I would go with dave blue's suggestion.
    Friday, December 5, 2014 11:04 PM
  • Hi, I am having a very similar issue, and while I understand the suggestion Dave made, this isnt a solution as I dont want to create a new table to store items normalized, I want the data saved denormalized as the model is nicely generated.

    So in my case I have a Entity called Event with a complex type Location and a referenced entity Coordinator:

    public class Event: EntityData {
        public string Coordinator_Id { get; set; }
        [ForeignKey("Coordinator_Id")]
        public virtual Coordinator Coordinator { get; set; }
        public DateTime EventDate { get; set; }
        public int Attendees { get; set; }    
        public Location Location { get; set; }
    }

    The Coordinator entity is corectly loaded and returned if I use Dave's suggestion, but this suggestion doesnt work to return the Location object, infact I get and exception if I try to $expand on Location

    Any new ideas here?

    Regards,

    Claiton


    Claiton Lovato

    Friday, September 4, 2015 4:25 PM