/// </summary>\r
/// <param name="connectionString">specifies file or server connection</param>\r
[DbLinqToDo]\r
- public DataContext(string connectionString)\r
+ public DataContext(string fileOrServerOrConnection)\r
{\r
Profiler.At("START DataContext(string)");\r
- IVendor ivendor = GetVendor(ref connectionString);\r
+ IVendor ivendor = GetVendor(ref fileOrServerOrConnection);\r
\r
- IDbConnection dbConnection = ivendor.CreateDbConnection(connectionString);\r
+ IDbConnection dbConnection = ivendor.CreateDbConnection(fileOrServerOrConnection);\r
Init(new DatabaseContext(dbConnection), null, ivendor);\r
\r
Profiler.At("END DataContext(string)");\r
System.Text.RegularExpressions.Regex reProvider\r
= new System.Text.RegularExpressions.Regex(@"DbLinqProvider=([\w\.]+);?");\r
\r
- string assemblyFile = null;\r
+ string assemblyName = null;\r
string vendor;\r
if (!reProvider.IsMatch(connectionString))\r
{\r
vendor = "SqlServer";\r
- assemblyFile = "DbLinq.SqlServer.dll";\r
+ assemblyName = "DbLinq.SqlServer";\r
}\r
else\r
{\r
var match = reProvider.Match(connectionString);\r
vendor = match.Groups[1].Value;\r
- assemblyFile = "DbLinq." + vendor + ".dll";\r
+ assemblyName = "DbLinq." + vendor;\r
\r
//plain DbLinq - non MONO: \r
//IVendor classes are in DLLs such as "DbLinq.MySql.dll"\r
#if MONO_STRICT\r
assembly = typeof (DataContext).Assembly; // System.Data.Linq.dll\r
#else\r
- //TODO: check if DLL is already loaded?\r
- assembly = Assembly.LoadFrom(assemblyFile);\r
+ assembly = Assembly.Load(assemblyName);\r
#endif\r
}\r
catch (Exception e)\r
{\r
throw new ArgumentException(\r
string.Format(\r
- "Unable to load the `{0}' DbLinq vendor within assembly `{1}'.",\r
- assemblyFile, vendor),\r
+ "Unable to load the `{0}' DbLinq vendor within assembly '{1}.dll'.",\r
+ assemblyName, vendor),\r
"connectionString", e);\r
}\r
}\r
_VendorProvider = ObjectFactory.Get<IVendorProvider>();\r
Vendor = vendor ?? \r
(connectionString != null ? GetVendor(ref connectionString) : null) ??\r
+#if MOBILE\r
+ _VendorProvider.FindVendorByProviderType(typeof(DbLinq.Sqlite.SqliteSqlProvider));\r
+#else\r
_VendorProvider.FindVendorByProviderType(typeof(SqlClient.Sql2005Provider));\r
+#endif\r
\r
DatabaseContext = databaseContext;\r
\r
SubmitChangesImpl(failureMode);\r
else\r
{\r
- using (IDatabaseTransaction transaction = DatabaseContext.Transaction())\r
+ using (IDbTransaction transaction = DatabaseContext.CreateTransaction())\r
{\r
try\r
{\r
- Transaction = (DbTransaction) transaction.Transaction;\r
+ Transaction = (DbTransaction) transaction;\r
SubmitChangesImpl(failureMode);\r
// TODO: handle conflicts (which can only occur when concurrency mode is implemented)\r
transaction.Commit();\r
}\r
}\r
\r
- private static MethodInfo _WhereMethod = typeof(Queryable).GetMethods().First(m => m.Name == "Where");\r
+ private static MethodInfo _WhereMethod;\r
internal object GetOtherTableQuery(Expression predicate, ParameterExpression parameter, Type otherTableType, IQueryable otherTable)\r
{\r
+ if (_WhereMethod == null)\r
+ System.Threading.Interlocked.CompareExchange (ref _WhereMethod, typeof(Queryable).GetMethods().First(m => m.Name == "Where"), null);\r
+\r
//predicate: other.EmployeeID== "WARTH"\r
Expression lambdaPredicate = Expression.Lambda(predicate, parameter);\r
//lambdaPredicate: other=>other.EmployeeID== "WARTH"\r
/// <summary>\r
/// Execute raw SQL query and return object\r
/// </summary>\r
- public IEnumerable<TResult> ExecuteQuery<TResult>(string query, params object[] parameters) where TResult : class, new()\r
+ public IEnumerable<TResult> ExecuteQuery<TResult>(string query, params object[] parameters) where TResult : new()\r
{\r
if (query == null)\r
throw new ArgumentNullException("query");\r
}\r
\r
private IEnumerable<TResult> CreateExecuteQueryEnumerable<TResult>(string query, object[] parameters)\r
- where TResult : class, new()\r
+ where TResult : new()\r
{\r
foreach (TResult result in ExecuteQuery(typeof(TResult), query, parameters))\r
yield return result;\r
set { throw new NotImplementedException(); }\r
}\r
\r
- public DbTransaction Transaction { get; set; }\r
+ public DbTransaction Transaction {\r
+ get { return (DbTransaction) DatabaseContext.CurrentTransaction; }\r
+ set { DatabaseContext.CurrentTransaction = value; }\r
+ }\r
\r
/// <summary>\r
/// Runs the given reader and returns columns.\r