This question is locked. New answers and comments are not allowed.
I have a database that is using several schemas. I was able to generate the classes with Reverse Mapping just fine, and also see the Schema name show up in the mappings.
For example, I have a table called AccountBase in a schema called ClientSetup. Here's the XML mapping:
However, when I query it by using the following:
I get the following error:
Telerik.OpenAccess.RT.sql.SQLException: Invalid object name 'AccountBase'
In the exception, the SQL that it's using is this (shortened for brevity):
It should have generated SQL that said FROM [ClientSetup].[AccountBase] instead.
Also, in our project, we have several different customers, and each customer can have their own separate database, and we store the connection strings for each customer in the database. We have a common database and several customer databases. I've had to make a custom ObjectScopeProvider (called CustomerScopeProvider) to handle this, and hopefully it is correct. I'm using the generated ObjectScopeProver class to handle all the Common database tasks.
Here's the code that I use to get an instance of the CustomerScopeProvider:
Is there something that I'm doing wrong that would cause it to not include the schema name in the query?
For example, I have a table called AccountBase in a schema called ClientSetup. Here's the XML mapping:
<class name="AccountBase"> |
<extension key="db-do-not-create-table" value="true" /> |
<extension key="db-table-name" value="ClientSetup.AccountBase" /> |
... |
</class> |
However, when I query it by using the following:
customerScope.Extent<AccountBase>(); |
I get the following error:
Telerik.OpenAccess.RT.sql.SQLException: Invalid object name 'AccountBase'
In the exception, the SQL that it's using is this (shortened for brevity):
SELECT a.[ID] AS COL1, ......, a.[WebSite] AS COL35 FROM [AccountBase] |
It should have generated SQL that said FROM [ClientSetup].[AccountBase] instead.
Also, in our project, we have several different customers, and each customer can have their own separate database, and we store the connection strings for each customer in the database. We have a common database and several customer databases. I've had to make a custom ObjectScopeProvider (called CustomerScopeProvider) to handle this, and hopefully it is correct. I'm using the generated ObjectScopeProver class to handle all the Common database tasks.
Here's the code that I use to get an instance of the CustomerScopeProvider:
public static IObjectScope GetPerRequestScope(HttpContextBase context, int customerId) |
{ |
IObjectScope commonScope = ObjectScopeProvider.GetPerRequestScope(context); |
var customer = commonScope.Extent<Customer>().Single(c => c.Id == customerId); |
string connection = string.Format("Data Source={0};Initial Catalog={1};User Id=user;Password=password", customer.DBServer, customer.DBName); |
string key = HttpContext.Current.GetHashCode().ToString("x") + Thread.CurrentContext.ContextID.ToString() + customerId.ToString(); |
IObjectScope scope; |
if (context == null) |
{ |
scope = Database.Get(connection, commonScope.Database.BackendConfiguration, commonScope.Database.MetaData).GetObjectScope(); |
} |
else |
{ |
scope = (IObjectScope)context.Items[key]; |
if (scope == null) |
{ |
scope = Database.Get(connection, commonScope.Database.BackendConfiguration, commonScope.Database.MetaData).GetObjectScope(); |
context.Items[key] = scope; |
} |
} |
return scope; |
} |
Is there something that I'm doing wrong that would cause it to not include the schema name in the query?