I'm using EF6 (Code First) to connect to a multi-tenanted database where each client has their own set of tables prefixed with a different schema name. Depending on who logs into the website, I change the connection string to a different user, who in turn has a default schema. Using this, I was hoping that if I had two tables - client1.Person and client2.Person - then I would just query the table 'Person' and the appropriate table would be queried depending on the login.
So, my first problem in EF6 was that all queries were prefixing the tables with 'dbo' - ie. 'dbo.Person'. No problem, I called modelBuilder.HasDefaultSchema("") to remove the schema name from the queries.
Now, I think this worked, but now the generated SQL prefixes the tables with 'CODEFIRSTDATABASE' - ie. 'CODEFIRSTDATABASE.Person'.
I am vaguely interested in what/why this is happening, but more importantly I simply want EF to query the database with NO schema information prepended - something that I thought would be a no-brainer.
BTW - I would also be happy to dynamically change the schema name when I open the connection HOWEVER, I should add that as well as the client-specific tables there are general 'system' tables which are shared amongst clients. In my code-first model, I specifically set those schema names using...
modelBuilder.Entity<SystemLog>().ToTable("SystemLog", "system");
...and obviously I don't want those changing dynamically.
Cheers,