Search code examples
c#asp.net-coreodataentity-framework-core

How to hide EF Context database schema via OData?


I'm using Microsoft.AspNetCore.OData 7.0.0-beta1 in an aspnetcore api.

Our EF context currently reflects the DB schema (legacy issue), however, the models we return via our standard API to the client are different to the entities. They only return a subset of fields and the properties are usually named differently to the columns.

Has anyone encountered this same issue? And if so what was your solution?

At the moment I'm thinking our best and easiest solution (but still alot of work as our DB schema is very large), is to create a new\seperate EF context and entities that reflect how we wan't to expose the OData schema to our clients and use that.

Any thoughts?


Solution

  • I would "create a new\seperate EF context and entities that reflect how we want to expose the OData schema to [your] clients and use that." If it's 1-1 entity-to-table, you can accomplish this with the mapping configuration in the model, or in a set of views in the database. If you need more substantial schema transformation, you may have to go with views and map to those.