Hi,
What is the best option to build an OData service on a legacy database?
All the tutorials are creating a database from scratch to match the entity framework model.
How does it work with an existing database that does not match the service model being exposed?
For example, I have these 2 db tables:
Science_Data { country_id varchar(3), year int, fig decimal }
Arts_Data { country_id varchar(3), year int, fig decimal }
and I want to expose it using this path /Category('Science')/Data and /Category('Arts')/Data (The ids are just for the example).
I was able to achieve some success by creating a service model that contains Category and Data entities and creating a controller:
public class CategoryController : ODataController { [EnableQuery] [ODataRoute("/Category('{id}')/Data")] public IQueryable<Sector> Get([FromODataUri]string id) { if (id == "Science") { return db.Science_Data.Select(i => new Data() { CountryId = i.country_id, Year = year, Figure = fig }); } else if(id == "Arts") { return db.Args_Data.Select(i => new Data() { CountryId = i.country_id, Year = year, Figure = fig }); } } }
This works to a certain extents and supports query options and the filtering will happen at the database level.
But I'm having problems supporting $expand options so I'm wondering if my approach is correct to begin with.
Thanks