I have this entity:
public class MyEntity
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
}
I want this entity to mapped into Oracle an oracle 11g database as MySchema.MyEntity
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<MyEntity>().ToTable("MyEntity", "MySchema");
base.OnModelCreating(modelBuilder);
}
The problem is that when I try to add an entity ,and do SaveChanges, it completely ignores the schema part of the ToTable(), even if I add a [Table(“MySchema.MyEntity”) ] attribute to the class it is also ignored. Schema will always be the login name of the connnection string regardless of what I do.
DbConnection con = new Devart.Data.Oracle.OracleConnection(
"User Id=system;Password=admin;Server=XE;Persist Security Info=true;");
The schema name is always what I set as UserId. It only changes if I write down explicitly that:
con.ChangeDatabase("MySchema"); //this will only work if the database connection is open...
But I do now want to write this down…
How to make this work?
EDIT:
Oh man… Solution :
First : UPPERCASESCHEMANAMES!!!
Second: In the offical dotconnect example there is a line:
config.Workarounds.IgnoreSchemaName = true;
Delete it… (this will only work if you set the schema name for ALL your entities, otherwise a “dbo” schema will be used that does not exist in oracle… )
kori0129, your solution is correct. The corresponding blog article is here: http://www.devart.com/blogs/dotconnect/index.php/entity-framework-code-first-support-for-oracle-mysql-postgresql-and-sqlite.html .
If you encounter any difficulties with the dotConnect for Oracle functionality, please contact us via http://www.devart.com/company/contact.html .