Accessing Oracle Synonyms Using Entity Framework 6 Code
I am currently working on a project that will use Entity Framework 6.1.1 and Oracle 11g database backend. I am accessing tables across multiple schemas, some of which have foreign key relationships between schemas (lookup tables, enterprise data, etc.).
Traditionally, we have used synonyms as a means of displaying these crosstab tables for a particular input. My question is ... how can I map these synonyms in EF6 using the first code mapping? I have no problem mapping tables directly within the same schema, but of course it won't be enough, since my tables intersect multiple schemas. So far my first code mappings do not recognize synonyms.
Has anyone been able to do code conversions to Oracle synonyms?
source to share
You can use the EF Fluent API to define the schema:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("MY_SCHEMA_NAME");
}
If you want to use Oracle synonyms, you can remove the schema:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema(string.Empty);
}
This will generate SQL containing FROM "MY_TABLE"
instead of FROM "dbo"."MY_TABLE"
orFROM "MY_SCHEMA_NAME"."MY_TABLE"
I use:
- EntityFramework 6.1.3
- Oracle.ManagedDataAccess 12.1.2400
- Oracle.ManagedDataAccess.EntityFramework 12.1.2400
source to share