EF Core 3.1 Navigation property to views

1.5k Views Asked by At

I know there are several questions similar to this one. But let me explain.

I am using Oracle and building a new Blazor app. The app has it own schema (a) but needs to read data from another schema (b) both on the same server.

The architect has decided to create views in schema a for all tables that's needed in schema b. Views are not mapped one to one, but the ID are always there. All views are read only. The application don't modify data outside it's own schema.

Can I some how trick EF Core to map to views and use them as navigation properties? I think it will be possible in EF Core 5 "Map entity types to queries" but are not sure.

1

There are 1 best solutions below

0
On

I've had success with views using EF core 5 by simply declaring the navigation property on the view class and then adding the [Foreignkey("PropertyName")] attribute to the ID in the view class that belongs to the navigation entity (where PropertyName is the name of the property in the view that represents the entity you want to join).