I have a LINQ to SQL DataContext that queries four different tables. But I need to move one of those tables to another database. Is it possible to have a database and connection string for certain tables and another for another table?
So right now I have something like:
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="DATABASE1")]
public partial class DataClassesDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
public DataClassesDataContext() : base(global::System.Configuration.ConfigurationManager.ConnectionStrings["DATABASE1ConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public DataClassesDataContext(string connection) : base(connection, mappingSource)
{
OnCreated();
}
}
So right now that handles all four tables. I would like for it to handle the first 3 tables and have another for the last. This possible?
Thanks!
Not directly; the most obvious thing would be to split the data-context into two separate data-context classes (and two dbml setups).
If you are careful, you could leave “as is”, and just explicitly supply the connection-string to each data-context instance, and just don’t use the wrong bits, however: this is risky. In particular, leaving it intact means you still might have queries that try to join between tables that are now in different databases, which won’t work.
The data-context here is only designed to work in a single database.