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.
Schema. The default schema that EF Core uses to create database objects is dbo . You can change this behaviour using the ModelBuilder 's HasDefaultSchema method: protected override void OnModelCreating(ModelBuilder modelBuilder)
The NotMapped attribute is used to specify that an entity or property is not to be mapped to a table or column in the database. In the following example, the AuditLog class will not be mapped to a table in the database: public class Contact.
HasDefaultSchema(ModelBuilder, String) Configures the default schema that database objects should be created in, if no schema is explicitly configured.
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:
You could use Fluent API to declare the default schema like the following:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("your_schema_here");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With