-1

Model looks like this:

public class Foo
{
    public long Id { get; set; }
    public ExpandoObject Attributes { get; set; }
}

What I get as a result from Web API call:

[
    {
        Id: 1,
        Attribute1: "XYZ",
        Attributes: "ABC"
    }
]

What I expect to get:

[
    {
        Id: 1,
        Attributes:
        {
            Attribute1: "XYZ",
            Attributes: "ABC"
        }
    }
]

Controller action returns IQueryable.

public IQueryable<Foo> Get()
{
    var result = ...;
    return result.AsQueryable();
}

result variable is a collection of Foo objects. Could anybody explain why does it happen?

mankers
  • 742
  • 10
  • 19
  • 1
    You are asking to put Id in the expando as well. Hard to see why that is necessary. Do consider the Json.NET library. – Hans Passant Sep 21 '18 at 11:06
  • Please post your controller action too. Which JSON serializer do you use? – Sphinxxx Sep 21 '18 at 11:21
  • @HansPassant Thanks for the response. Now I see how it looks like, but the real model is much bigger, this one was created for simplicity purposes. – mankers Sep 21 '18 at 11:58
  • @Sphinxxx Thanks for your response. The action is not complicated, I've edited my question. – mankers Sep 21 '18 at 12:02

1 Answers1

0

Ok, I found one solution. I'm pretty sure not the best, but working.

I introduced a class containing only one property:

public class Bar
{
    public ExapndoObject Content { get; set; }
}

and used it in Foo class:

public class Foo
{
    public long Id { get; set; }
    public Bar Attributes { get; set; }
}

Anyway, I'm still interested in better solutions.

mankers
  • 742
  • 10
  • 19