This question is locked. New answers and comments are not allowed.
Richard Koslik
Top achievements
Rank 1
Richard Koslik
asked on 20 Jul 2010, 09:50 AM
Hello,
i have two databases with the same Tables inside. One is Oracle the other MsSql (a 3rd should be later MySql).
My goal is to select in the web.config file (or somewhere else) the database to use (depending on the endcustomer).
After solving manage the connectionStrings in the web.config file my problem is now how to change the backend config string in the generated code of the DomainModel.cs.
Since this code is generated automaticaly i need a solution where i can define the string to use somewhere else.
Any suggestions, please?
i have two databases with the same Tables inside. One is Oracle the other MsSql (a 3rd should be later MySql).
My goal is to select in the web.config file (or somewhere else) the database to use (depending on the endcustomer).
After solving manage the connectionStrings in the web.config file my problem is now how to change the backend config string in the generated code of the DomainModel.cs.
public static BackendConfiguration GetBackendConfiguration()
{
BackendConfiguration backend = new BackendConfiguration();
backend.Backend = "mssql"; // "oracle"; // "mysql";
return backend;
}
Since this code is generated automaticaly i need a solution where i can define the string to use somewhere else.
Any suggestions, please?
6 Answers, 1 is accepted
0
Hi Richard Koslik,
You do not actually need to change the anything in this method. You can just specify which backend you want to use by passing a backend configuration to the constructor of the context. I guess you will have to pass the connection string (or only the connection string name) and a metadata source as well:
Hope that helps.
Greetings,
Alexander
the Telerik team
You do not actually need to change the anything in this method. You can just specify which backend you want to use by passing a backend configuration to the constructor of the context. I guess you will have to pass the connection string (or only the connection string name) and a metadata source as well:
XmlMetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource(
"EntityDiagrams1.rlinq"
);
string
connectionString =
string
.Empty;
BackendConfiguration dbConfig =
new
BackendConfiguration();
if
(useMssql)
{
connectionString =
"MssqlConnectionString"
;
dbConfig.Backend =
"mssql"
;
}
else
{
connectionString =
"OracleConnectionString"
;
dbConfig.Backend =
"oracle"
;
}
EntityDiagrams1 context =
new
EntityDiagrams1(connectionString, dbConfig, metadataSource);
Greetings,
Alexander
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Richard Koslik
Top achievements
Rank 1
answered on 21 Jul 2010, 10:25 AM
Hello!
Which constructor do you mean and where do I use then the "context"-variable? You can see the files of my project in the screenshot below.
- ORM => the DomainModel
- ORMDomainService => the DomainService
- CUSTOMER_NEW => my table in the database
Thanks for your help!
Which constructor do you mean and where do I use then the "context"-variable? You can see the files of my project in the screenshot below.
- ORM => the DomainModel
- ORMDomainService => the DomainService
- CUSTOMER_NEW => my table in the database
Thanks for your help!
0
Hi Richard,
The context constructor that I meant is on the last row of the sample code from my last post. The context itself is a class which you can use to manage the persistent objects (add, delete, modify). It is automatically generated by OpenAccess and can be found in a .cs (vb) file with the same name as the .rlinq file. In your case it is generated in the ORM.cs file. The context class uses the same name as the name of the connection string you have set in the Add new item wizard.
You can find more details about handling the context and persistent classes instances in the OpenAccess ORM Visual Designer -> Programming Guide -> OpenAccess Tasks -> Working with Objects chapter of the documentation installed locally on your machine. Currently our online documentation is not the latest available version but will be updated soon.
Regards,
Alexander
the Telerik team
The context constructor that I meant is on the last row of the sample code from my last post. The context itself is a class which you can use to manage the persistent objects (add, delete, modify). It is automatically generated by OpenAccess and can be found in a .cs (vb) file with the same name as the .rlinq file. In your case it is generated in the ORM.cs file. The context class uses the same name as the name of the connection string you have set in the Add new item wizard.
You can find more details about handling the context and persistent classes instances in the OpenAccess ORM Visual Designer -> Programming Guide -> OpenAccess Tasks -> Working with Objects chapter of the documentation installed locally on your machine. Currently our online documentation is not the latest available version but will be updated soon.
Regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Richard Koslik
Top achievements
Rank 1
answered on 26 Jul 2010, 07:57 AM
Hello!
I tried now to find out, how I can use the example, but I have no idea!
This is my auto-generated class, with the constructors (there is also the constructor with the three parameters, which should be used as in your example):
public partial class ORMDbContext : OpenAccessContext
{
private static string connectionStringName = "EntityDiagrams";
private static BackendConfiguration backend = GetBackendConfiguration();
private static MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource("ORM.rlinq");
public ORMDbContext() : base(connectionStringName, backend, metadataSource)
{ }
public ORMDbContext(string connection) : base (connection, backend, metadataSource)
{ }
public ORMDbContext(BackendConfiguration backendConfiguration) : base(connectionStringName, backendConfiguration, metadataSource)
{ }
public ORMDbContext(string connection, MetadataSource metadataSource) : base(connection, backend, metadataSource)
{ }
public ORMDbContext(string connection, BackendConfiguration backendConfiguration, MetadataSource metadataSource)
:base(connection, backendConfiguration, metadataSource)
{ }
....
And this is the service class where the ORMDbContext is used/generated (create Telerik ORM Service Model):
[EnabledClientAccess()]
public partial class ORMDomainService : OpenAccessDomainService< ORMDBContext >
{
public ORMDomainService() : base()
{ }
.....
How can I now manage that the right constructor is used. Or how can I initialize the "connectionsstring" and "backendconfiguration"???Do you now understand me???
Thanks for your answer!
I tried now to find out, how I can use the example, but I have no idea!
This is my auto-generated class, with the constructors (there is also the constructor with the three parameters, which should be used as in your example):
public partial class ORMDbContext : OpenAccessContext
{
private static string connectionStringName = "EntityDiagrams";
private static BackendConfiguration backend = GetBackendConfiguration();
private static MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource("ORM.rlinq");
public ORMDbContext() : base(connectionStringName, backend, metadataSource)
{ }
public ORMDbContext(string connection) : base (connection, backend, metadataSource)
{ }
public ORMDbContext(BackendConfiguration backendConfiguration) : base(connectionStringName, backendConfiguration, metadataSource)
{ }
public ORMDbContext(string connection, MetadataSource metadataSource) : base(connection, backend, metadataSource)
{ }
public ORMDbContext(string connection, BackendConfiguration backendConfiguration, MetadataSource metadataSource)
:base(connection, backendConfiguration, metadataSource)
{ }
....
And this is the service class where the ORMDbContext is used/generated (create Telerik ORM Service Model):
[EnabledClientAccess()]
public partial class ORMDomainService : OpenAccessDomainService< ORMDBContext >
{
public ORMDomainService() : base()
{ }
.....
How can I now manage that the right constructor is used. Or how can I initialize the "connectionsstring" and "backendconfiguration"???Do you now understand me???
Thanks for your answer!
0
Accepted
Hello Richard Koslik,
Sorry, I did not notice that you are using a domain service. In this case you can override the CreateDataContext() virtual method of the OpenAccessDomainService<T> class and instantiate the context the way you want, using the appropriate constructor. To do this you will have to create a new .cs file with a ORMDomainService partial class inside and override the method there:
Having this partial class in a separate file will ensure that the code is not lost if the domain context is regenerated. Hope that helps.
Greetings,
Alexander
the Telerik team
Sorry, I did not notice that you are using a domain service. In this case you can override the CreateDataContext() virtual method of the OpenAccessDomainService<T> class and instantiate the context the way you want, using the appropriate constructor. To do this you will have to create a new .cs file with a ORMDomainService partial class inside and override the method there:
public
partial
class
ORMDomainService
{
protected
override
ORMDbContext CreateDataContext()
{
XmlMetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource(
"ORM.rlinq"
);
string
connectionString =
string
.Empty;
BackendConfiguration dbConfig =
new
BackendConfiguration();
if
(useMssql)
{
connectionString =
"MsSqlConnectionString"
;
dbConfig.Backend =
"mssql"
;
}
else
{
connectionString =
"OracleConnectionString"
;
dbConfig.Backend =
"oracle"
;
}
return
new
ORMDbContext (connectionString, dbConfig, metadataSource);
}
}
Greetings,
Alexander
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Richard Koslik
Top achievements
Rank 1
answered on 27 Jul 2010, 10:33 AM
Thanks for your help, now it works!