This commit is contained in:
grzegorz.russek
2019-10-11 10:57:11 +00:00
parent c35b6b2d72
commit d1193cba01
5 changed files with 106 additions and 25 deletions

View File

@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamORM", "DynamORM\DynamORM.csproj", "{63963ED7-9C78-4672-A4D4-339B6E825503}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamORM.Tests", "DynamORM.Tests\DynamORM.Tests.csproj", "{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}"
@@ -9,6 +11,8 @@ 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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -29,6 +33,16 @@ Global
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|x86.ActiveCfg = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|x86.ActiveCfg = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Any CPU.Build.0 = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|x86.ActiveCfg = Release|Any CPU
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Any CPU.ActiveCfg = Debug|x86
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Any CPU.Build.0 = Debug|x86
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
@@ -41,16 +55,6 @@ Global
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Mixed Platforms.Build.0 = Release|x86
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.ActiveCfg = Release|x86
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.Build.0 = Release|x86
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|x86.ActiveCfg = Debug|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Any CPU.Build.0 = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|x86.ActiveCfg = Release|Any CPU
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Any CPU.ActiveCfg = Debug|x86
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.Build.0 = Debug|x86
@@ -61,11 +65,26 @@ 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
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Tester\Tester.csproj
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B94FC164-4357-4FDA-A844-5202FA8C5E4B}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Tester\Tester.csproj
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Description>Dynamic Object-Relational Mapping library.</Description>
<Copyright>Copyright © RUSSEK Software 2012-2019</Copyright>
<Company>RUSSEK Software</Company>
<Authors>Grzegorz Russek</Authors>
<FileVersion>1.1.0.1</FileVersion>
<AssemblyVersion>1.1.0.1</AssemblyVersion>
<RepositoryUrl>https://dr4cul4.pl/svn/DynamORM/</RepositoryUrl>
<PackageProjectUrl>https://dr4cul4.pl</PackageProjectUrl>
<Product>DynamORM</Product>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>

View File

@@ -33,6 +33,7 @@ using System.Data;
using System.Data.Common;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Text;
using DynamORM.Builders;
using DynamORM.Builders.Extensions;
@@ -166,19 +167,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);
@@ -1441,7 +1484,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();

View File

@@ -45,7 +45,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("RUSSEK Software")]
[assembly: AssemblyProduct("DynamORM")]
[assembly: AssemblyCopyright("Copyright © RUSSEK Software 2012")]
[assembly: AssemblyCopyright("Copyright © RUSSEK Software 2012-2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@@ -21,7 +21,9 @@ namespace Tester
private static void Main(string[] args)
{
DynamicDatabase db = new DynamicDatabase(System.Data.SqlClient.SqlClientFactory.Instance, "packet size=4096;User Id=sa;Password=Sa123;data source=127.0.0.1,1434;initial catalog=MAH_Levant;",
var c = new System.Data.SqlClient.SqlConnection("packet size=4096;User Id=sa;Password=Sa123;data source=127.0.0.1,1434;initial catalog=MAH_Levant;");
DynamicDatabase db = new DynamicDatabase(c,
DynamicDatabaseOptions.SingleConnection | DynamicDatabaseOptions.SingleTransaction | DynamicDatabaseOptions.SupportSchema |
DynamicDatabaseOptions.SupportStoredProcedures | DynamicDatabaseOptions.SupportTop | DynamicDatabaseOptions.DumpCommands);