0

Visual Studio created this code for me:

    // GET: api/building/5
    [ResponseType(typeof(building))]
    public IHttpActionResult Getbuilding(int id)
    {
        building building = db.buildings.Find(id);

        if (building == null)
        {
            return NotFound();
        }

        return Ok(building);
    }

Each building can have a number images. Those images live in the table buildingimages that looks like this:

| id | building_id | image   |
------------------------------
| 0  |   76        | bob.jpg |

How can I load the related images along with the building, given the above code?

I've looked around, but none of the examples look exactly like my generated code. I suspect I'm just not using the right keywords and that the answer is blindingly simple.

0

1 Answer 1

0

Is that building class generated by EntityFramework? If so you should have added a foreign key for building_id column on the buildingimages. Thus EntityFramework would create a collection in the building class for images.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.