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.

crowhill
  • 2,398
  • 3
  • 26
  • 55

1 Answers1

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.