This commit is contained in:
@@ -1626,19 +1626,61 @@ namespace DynamORM
|
||||
InitCommon(connectionString, options);
|
||||
}
|
||||
|
||||
private DbProviderFactory FindDbProviderFactoryFromConnection(Type t)
|
||||
{
|
||||
foreach (var type in t.Assembly.GetTypes().Where(x => x.IsSubclassOf(typeof(DbProviderFactory))))
|
||||
{
|
||||
DbProviderFactory provider = null;
|
||||
bool dispose = false;
|
||||
|
||||
var pi = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty);
|
||||
if (pi != null)
|
||||
provider = (DbProviderFactory)pi.GetValue(null, null);
|
||||
else
|
||||
{
|
||||
var fi = type.GetField("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField);
|
||||
if (fi != null)
|
||||
provider = (DbProviderFactory)fi.GetValue(null);
|
||||
}
|
||||
|
||||
if (provider == null)
|
||||
{
|
||||
var ci = type.GetConstructor(Type.EmptyTypes);
|
||||
if (ci != null)
|
||||
{
|
||||
provider = ci.Invoke(null) as DbProviderFactory;
|
||||
dispose = true;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (provider != null)
|
||||
{
|
||||
using (var c = provider.CreateConnection())
|
||||
{
|
||||
if (c.GetType() == t)
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (provider != null && dispose && provider is IDisposable)
|
||||
((IDisposable)provider).Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="DynamicDatabase" /> class.</summary>
|
||||
/// <param name="connection">Active database connection.</param>
|
||||
/// <param name="options">Connection options. <see cref="DynamicDatabaseOptions.SingleConnection"/> required.</param>
|
||||
public DynamicDatabase(IDbConnection connection, DynamicDatabaseOptions options)
|
||||
{
|
||||
// Try to find correct provider if possible
|
||||
Type t = connection.GetType();
|
||||
if (t == typeof(System.Data.SqlClient.SqlConnection))
|
||||
_provider = System.Data.SqlClient.SqlClientFactory.Instance;
|
||||
else if (t == typeof(System.Data.Odbc.OdbcConnection))
|
||||
_provider = System.Data.Odbc.OdbcFactory.Instance;
|
||||
else if (t == typeof(System.Data.OleDb.OleDbConnection))
|
||||
_provider = System.Data.OleDb.OleDbFactory.Instance;
|
||||
_provider = FindDbProviderFactoryFromConnection(connection.GetType());
|
||||
|
||||
IsDisposed = false;
|
||||
InitCommon(connection.ConnectionString, options);
|
||||
@@ -2901,7 +2943,7 @@ namespace DynamORM
|
||||
Type type = (Type)schema.DATATYPE;
|
||||
|
||||
// Small hack for SQL Server Provider
|
||||
if (type == typeof(string) && Provider != null && Provider.GetType() == typeof(System.Data.SqlClient.SqlClientFactory))
|
||||
if (type == typeof(string) && Provider != null && Provider.GetType().Name == "SqlClientFactory")
|
||||
{
|
||||
var map = schema as IDictionary<string, object>;
|
||||
string typeName = (map.TryGetValue("DATATYPENAME") ?? string.Empty).ToString();
|
||||
@@ -4574,9 +4616,6 @@ namespace DynamORM
|
||||
/// <returns>Converted object.</returns>
|
||||
public static dynamic ToDynamic(this object o)
|
||||
{
|
||||
if (o == null)
|
||||
return null;
|
||||
|
||||
Type ot = o.GetType();
|
||||
|
||||
if (ot == typeof(DynamicExpando) || ot == typeof(ExpandoObject))
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace AmalgamationTool
|
||||
//}
|
||||
//else
|
||||
{
|
||||
if (content.Trim().Length == 0)
|
||||
continue;
|
||||
|
||||
var nstart = content.IndexOf("namespace ") + "namespace ".Length;
|
||||
var bbrace = content.IndexOf("{", nstart);
|
||||
var nlen = bbrace - nstart;
|
||||
|
||||
@@ -14,4 +14,9 @@
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\AmalgamationTool\DynamORM.Amalgamation.cs" Link="DynamORM.Amalgamation.cs" />
|
||||
<Compile Include="..\DynamORM\Properties\AssemblyInfo.cs" Link="AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
28
DynamORM.sln
28
DynamORM.sln
@@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AmalgamationTool", "Amalgam
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester", "Tester\Tester.csproj", "{F747AA57-BEA7-4FB8-B371-546296789AEF}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamORM.Core", "DynamORM\DynamORM.Core.csproj", "{90D18618-B92E-41E5-9099-A7352E4E5C18}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamORM.Core", "DynamORM.Core\DynamORM.Core.csproj", "{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -65,24 +65,24 @@ Global
|
||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.ActiveCfg = Release|x86
|
||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.Build.0 = Release|x86
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{90D18618-B92E-41E5-9099-A7352E4E5C18}.Release|x86.Build.0 = Release|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A0D69E18-0D0A-47EB-8E4D-EDD9B73752A1}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B94FC164-4357-4FDA-A844-5202FA8C5E4B}
|
||||
SolutionGuid = {22781EB3-2148-4CA4-845A-B55265A7B5C2}
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Tester\Tester.csproj
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -12,7 +12,7 @@
|
||||
<AssemblyName>DynamORM</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<DelaySign>False</DelaySign>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
@@ -33,6 +33,7 @@
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>PdbOnly</DebugType>
|
||||
@@ -48,6 +49,7 @@
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
@@ -60,7 +62,9 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data">
|
||||
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user