On Tue, 2009-03-03 at 20:12 +0100, Pascal Craponne wrote:
> I had in mind that the IDbConnection.ConnectionString was a string, so
> it could be handled the same way... :)

It took me awhile to understand what you were getting at, but I like
that idea.

How's this patch look?

 - Jon


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: src/DbLinq/Data/Linq/DataContext.cs
===================================================================
--- src/DbLinq/Data/Linq/DataContext.cs	(revision 982)
+++ src/DbLinq/Data/Linq/DataContext.cs	(working copy)
@@ -126,10 +126,19 @@
         [DbLinqToDo]
         public DataContext(string connectionString)
         {
-            #region DataContext connectionString ctor
-            if (connectionString == null)
-                throw new ArgumentNullException("connectionString");
+            IVendor ivendor = GetVendor(connectionString);
+            IDbConnection dbConnection = ivendor.CreateDbConnection(connectionString);
+            Init(new DatabaseContext(dbConnection), null, ivendor);
+        }
 
+        private IVendor GetVendor(string connectionString)
+        {
+            #region DataContext connectionString ctor
+
+            if (connectionString == null)
+
+                throw new ArgumentNullException("connectionString");
+
             System.Text.RegularExpressions.Regex reProvider
                 = new System.Text.RegularExpressions.Regex(@"DbLinqProvider=([\w\.]+)");
 
@@ -184,7 +193,7 @@
             {
                 //TODO: add proper logging here
                 Console.WriteLine("DataContext ctor: Assembly load failed for " + assemblyToLoad + ": " + ex);
-                throw ex;
+                throw;
             }
 
             //find IDbProvider class in this assembly:
@@ -219,9 +228,9 @@
                 throw ex;
             }
             IVendor ivendor = (IVendor)ivendorObject;
-            IDbConnection dbConnection = ivendor.CreateDbConnection(connectionString);
-            Init(new DatabaseContext(dbConnection), null, ivendor);
-            #endregion
+            return ivendor;
+            #endregion
+
         }
 
         private void Init(IDatabaseContext databaseContext, MappingSource mappingSource, IVendor vendor)
@@ -231,9 +240,9 @@
 
             _VendorProvider = ObjectFactory.Get<IVendorProvider>();
             if (vendor == null)
-                Vendor = _VendorProvider.FindVendorByProviderType(typeof(SqlClient.Sql2005Provider));
-            else
-                Vendor = vendor;
+                vendor = GetVendor(databaseContext.Connection.ConnectionString) ?? 
+                    _VendorProvider.FindVendorByProviderType(typeof(SqlClient.Sql2005Provider));
+            Vendor = vendor;
 
             DatabaseContext = databaseContext;
 

Reply via email to