简体   繁体   中英

Query a related entity by id in Entity Framework

I use the c# web api in combination with the entity framework. The http requests are generated by the sap ui5 framework. The generated get request looks like: "http://localhost:52854/KddietzTourenplan/5/KddietzTour/1" How must the name of the associated method and parameters?

    [EnableQuery]
    public IQueryable<KddietzTour> GetKddietzTour([FromODataUri] int key, ???)
    {
        return _oContext.KddietzTour.AsQueryable().Where(p => p.NTourenplanId == key);
    }

I know, the simplest request would be "http://localhost:52854/KddietzTour/1". But as mentioned before, the requests are generated from another framework.

You need to use HttpGet Attribute to map the URL to the method and its parameters. to map the parameters you need to use {ParameterName} inside the template you're using in HttpGet

[EnableQuery]
[HttpGet("KddietzTourenplan/5/KddietzTour/{key}")]
public IQueryable<KddietzTour> GetKddietzTour([FromODataUri] int key, ???)
{
    return _oContext.KddietzTour.AsQueryable().Where(p => p.NTourenplanId == key);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM