Best place to set DataContext connection string?
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Best place to set DataContext connection string?
I am using Entity Developer Linq to SQL and I wanted to know where is the best place tell the DataContext what connection string to use? I am guessing in the partial class I can implement OnCreated and set the connection string there? I created the model with the entity developer designer then added the .lqml file to visual studio project, I wonder if I can recreated it so it is class per file, I don't see an empty partial class for the datacontext but I do see the partial created by the designer. Is there some setting in the designer setting I need to change to create the empty partial, the one the designer will not override?
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Re: Best place to set DataContext connection string?
Why does updating the model from the database create invalid code and using statements?
using System.Data.Linq;
using System.Data.Linq.Mapping;
[System.Data.Linq.Mapping.DatabaseAttribute
Shouldn't that be Devart.Data.Linq and Devart.Data.Linq.Mapping?
using System.Data.Linq;
using System.Data.Linq.Mapping;
[System.Data.Linq.Mapping.DatabaseAttribute
Shouldn't that be Devart.Data.Linq and Devart.Data.Linq.Mapping?
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Re: Best place to set DataContext connection string?
I am using Visual Studio 2015 and v5.8.762 of Entity Developer.OutOfTouch6947 wrote:Why does updating the model from the database create invalid code and using statements?
using System.Data.Linq;
using System.Data.Linq.Mapping;
[System.Data.Linq.Mapping.DatabaseAttribute
Shouldn't that be Devart.Data.Linq and Devart.Data.Linq.Mapping?
Ok I see I am confused, I am using the Linq To Sql Template not the LinqConnect template, the code being generated does not match what should be Linq To Sql how do I fix it?
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Re: Best place to set DataContext connection string?
What versions of the Devart dll's should I have referenced? Where are they devart dlls? I didn't see them in GAC.
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Re: Best place to set DataContext connection string?
I am convinced your Linq to SQL template doesn't generate the correct code.
This is what I end up with in my using statements.
using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.ComponentModel;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
This is what I end up with in my using statements.
using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.ComponentModel;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Re: Best place to set DataContext connection string?
The only thing that worked was to delete the model and recreate it from the database.OutOfTouch6947 wrote:I am convinced your Linq to SQL template doesn't generate the correct code.
This is what I end up with in my using statements.
using System;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.ComponentModel;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
Re: Best place to set DataContext connection string?
You can set connection via Entity Developer:I am using Entity Developer Linq to SQL and I wanted to know where is the best place tell the DataContext what connection string to use?
- check that "Use the following connection string from App.Config" is selected in the Model Properties;
- open Database Explorer and right-click on Database Connection-> Edit Connection Properties;
- change connection to the necessary one and save the changes.
Also you can set connection in the code:
Code: Select all
TestDataContext context = new TestDataContext(connectionString);
Set the "Generate Partial Class" option to True in the Properties of the used template and the files of the partial classes will be generated (these files are generated only once when the model is created and they are not regenerated after any changes to the model to save your manual changes).I wonder if I can recreated it so it is class per file, I don't see an empty partial class for the datacontext but I do see the partial created by the designer. Is there some setting in the designer setting I need to change to create the empty partial, the one the designer will not override?
No, it shouldn't. LinqConnect is our own ORM solution, closely compatible to Microsoft LINQ to SQL: http://www.devart.com/linqconnect/ .Shouldn't that be Devart.Data.Linq and Devart.Data.Linq.Mapping?
LinqConnect provides support for SQL Server, Oracle, MySQL, PostgreSQL and SQLite, and includes visual model designer - Entity Developer. With Entity Developer which is bundled with LinqConnect, you will be able to work with the LinqConnect models against SQL Server (Standard edition) and Oracle, MySQL, PostgreSQL and SQLite (Professional edition).
There is no LinqConnect support in Entity Developer Professional (separate product). Entity Developer Professional Edition allows designing models for NHibernate, Entity Framework, and LINQ to SQL (not LinqConnect):
http://www.devart.com/entitydeveloper/editions.html
You shouldn't add any Devart assemblies when working with Entity Developer and LINQ to SQL. Devart assemblies are required for LinqConnect support.What versions of the Devart dll's should I have referenced? Where are they devart dlls? I didn't see them in GAC.
Please describe the exact steps you are performing, send us the exact code you are getting after these steps and the code you are expecting to get.I am convinced your Linq to SQL template doesn't generate the correct code.
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Re: Best place to set DataContext connection string?
I do have the connection string using app.config.
I will have different connection strings for development and production as well as the need to encrypt and decrypt my connection string with code, so I am wondering where is the best place in a Partial Class for DataContext to set this? OnCreated?
It created the partials, my mistake.
I will have different connection strings for development and production as well as the need to encrypt and decrypt my connection string with code, so I am wondering where is the best place in a Partial Class for DataContext to set this? OnCreated?
It created the partials, my mistake.
Last edited by OutOfTouch6947 on Thu 21 Jan 2016 15:53, edited 1 time in total.
-
- Posts: 79
- Joined: Tue 02 Jun 2015 18:22
Re: Best place to set DataContext connection string?
As far as the template goes all I did was create it with Entity Developer Designer then added the .lqml file to my project, I must have done something wrong after I recreated it, it was using the correct template and generating the correct code.
Re: Best place to set DataContext connection string?
Yes, you can use the partial class and OnCreated() method:
https://www.devart.com/linqconnect/docs ... thods.html
You can also try passing one or another connection string to your data context constructor, depending on where the code is being executed (at the local development machine or at the production server), for example, using the compilation conditions for this:
This code will determine what connection string to use according to the solution configuration (Debug or Release). And then create your DataContext object using the necessary connection string.
The choice of possible options for such scenario depends on your specific aspects, preferences, etc.
If you have any further questions, feel free to contact us.
https://www.devart.com/linqconnect/docs ... thods.html
You can also try passing one or another connection string to your data context constructor, depending on where the code is being executed (at the local development machine or at the production server), for example, using the compilation conditions for this:
Code: Select all
#if DEBUG
static string connectionString = "data source = localhost; ..."; //put here the necessary connection string
#else
static string connectionString = "data source = Mylocalhost; ..."; //put here the necessary connection string
#endif
The choice of possible options for such scenario depends on your specific aspects, preferences, etc.
If you have any further questions, feel free to contact us.