Use one model with multiple Schema

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
lc4pro
Posts: 51
Joined: Thu 12 Jul 2012 08:16

Use one model with multiple Schema

Post by lc4pro » Thu 09 Aug 2012 07:57

Hi,

how can we use one generated model with multiple MySQL schemes?

We tried to get this working like described here (as it's a similar problem):
http://forums.devart.com/viewtopic.php?f=31&t=24588

After we switched the mapping mode to file, it still won't work using another schema by using a different connection string.
Here is our code so far (we are using the manifest variant described here: http://www.devart.com/linqconnect/docs/POCO.html):

Code: Select all

Stream contextStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Samplenamespace.SampleDataContext.xml");
Devart.Data.Linq.Mapping.MappingSource mappingSource = Devart.Data.Linq.Mapping.XmlMappingSource.FromStream(contextStream);
SampleDataContext db = new SampleDataContext(WebConfigurationManager.ConnectionStrings["SampleData"].ToString(), mappingSource);

int count = db.MySampleTable.Count();
It always tries to connect to the scheme we used when we created it.
The only solution that worked was to manually rename the schema in the created xml file, but we need to specify the schema in the web.config file...

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Use one model with multiple Schema

Post by MariiaI » Thu 09 Aug 2012 11:08

The problem is that by default the schema name is stored in the mapping (this is done to cover the case of having objects from different schemas in the same model). Thus, having different mapping files won't help, unless you specify the new schema name in each of them.

In your case you should disable the schema name in your model. To do this:
- double-click on the diagram canvas to open Model Settings;
- uncheck the "Preserve schema name in storage" option;
- save changes.

After these steps, you have to re-create your model in order to changes become effective for all Entity classes. Use "Update Model from Database" wizard with the selected "Recreate Model" option.

In this case queries will be executed to the schema, which is specified in the connection string.

Please let us know if this helps.

Post Reply