Reputation: 870
I am using Entity Framework 6 Code First to connect to an oracle database. EF is using "dbo" as the schema. I would rather not specify the schema, but rather let Oracle resolve the schema from the connection string.
Is there a way to omit "dbo" or any schema from the queries?
Example Given: Instead of "select * from dbo.table" I would like to see "select * from table".
Currently, I am parsing the connection string for the userId and using that as the schema, but I'd prefer to not use this technique.
Upvotes: 6
Views: 1333
Reputation: 387
FrankO's answer is correct in that you can specify the default schema using the Fluent API.
In addition, this same method, in my experience, can be utilized to remove the default schema, allowing Oracle to resolve the schema in the case that it is specified on the connect string or if your companies policy is to access all tables through a public synonym.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema(string.Empty);
}
This would produce SQL containing FROM "MY_TABLE"
instead of FROM "dbo"."MY_TABLE"
I'm using:
Upvotes: 6
Reputation: 2562
You could use Fluent API to declare the default schema like the following:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("your_schema_here");
}
Upvotes: 1