Single Data Context for Multiple Databases and Environments
Single Data Context for Multiple Databases and Environments
How I make the DataContext dynamic?
This is critical to the way our organisation works, we can't afford to create new data contexts classes for every environment we have. We have dev, uat, training and production environments, this is also replicated accross databases for the same entities (tables).
The data context file decorates the class with a Table attribute which is environment specific, e.g [Table(Name = @"0123DEV.EMPLOYEE")]; how do we modify this at runtime to provide a very dynamic class?
Is this possible with LINQ to Oracle? If it isn't then it is a major flaw as to how ORACLE invokes it's voodoo and would be detrimental to our organisation and will have to scrap the use of LINQ.
Thanks in advance!
Regards
Matthew
This is critical to the way our organisation works, we can't afford to create new data contexts classes for every environment we have. We have dev, uat, training and production environments, this is also replicated accross databases for the same entities (tables).
The data context file decorates the class with a Table attribute which is environment specific, e.g [Table(Name = @"0123DEV.EMPLOYEE")]; how do we modify this at runtime to provide a very dynamic class?
Is this possible with LINQ to Oracle? If it isn't then it is a major flaw as to how ORACLE invokes it's voodoo and would be detrimental to our organisation and will have to scrap the use of LINQ.
Thanks in advance!
Regards
Matthew
I have just tried to remove the schema name and succeeded in querying a database.
The only scenario when this workaround cannot help is when one connects as user1 and needs to operate with the tables owned by user2.
In this case I recommend you to create either public (if you need this table to be visible for several users) or
user-specific synonym.
One more possible way (dynamic attribute setting) is described here:
http://geekswithblogs.net/abhijeetp/arc ... -in-c.aspx
The only scenario when this workaround cannot help is when one connects as user1 and needs to operate with the tables owned by user2.
In this case I recommend you to create either public (if you need this table to be visible for several users) or
user-specific synonym.
One more possible way (dynamic attribute setting) is described here:
http://geekswithblogs.net/abhijeetp/arc ... -in-c.aspx
Was your test done with Oracle? I'm not sure how you can query an Oracle DB without a schema name the database table are actually prefixed with the schema name....
Below is a simple example of what I am trying to do
public List GetContacts()
{
using (SetupDataContext ctx = new SetupDataContext(_connString))
{
List userEntity = new List();
var user =
(from c in ctx.CONTACTs
select c).ToList();
return user;
}
}
catch (Exception ex)
{
//Handle exception }
}
The above method fails if you remove the schema name in the datacontext file.
P.S. my connection string is the same user as the connection string used to create the datacontext via entity developer. I get error message ORA-00942: table or view does not exist"
Below is a simple example of what I am trying to do
public List GetContacts()
{
using (SetupDataContext ctx = new SetupDataContext(_connString))
{
List userEntity = new List();
var user =
(from c in ctx.CONTACTs
select c).ToList();
return user;
}
}
catch (Exception ex)
{
//Handle exception }
}
The above method fails if you remove the schema name in the datacontext file.
P.S. my connection string is the same user as the connection string used to create the datacontext via entity developer. I get error message ORA-00942: table or view does not exist"
Thanks for your assistance. Removing the schema name isn't a fix as I previously mentioned. Oracle tables are associated with the schema e.g. 123.CONTACT and 456.CONTACT within the database are different tables; by referring to them as CONTACT is insufficient and does throw an exception.
Perhaps there's no work around
Perhaps there's no work around
One more suggestion.
Try to execute the following command
on DataContext.Connection.
This will let you use table 123.Contact.
You will have to remove Schema attributes for the necessary tables.
Try to execute the following command
Code: Select all
ALTER SESSION SET CURRENT_SCHEMA = "123"This will let you use table 123.Contact.
You will have to remove Schema attributes for the necessary tables.
We have released the new 6.30.160 build of dotConnect for Oracle. This build can be dowloaded from here (the trial version) or from Registered Users' Area (for users with active subscription only).
For the detailed information about the improvements and fixes available in dotConnect for Oracle 6.30.160, please refer to this announcement.
For the detailed information about the improvements and fixes available in dotConnect for Oracle 6.30.160, please refer to this announcement.