Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/DapperDal/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="oracle.manageddataaccess.client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</configSections>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client"/>
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.122.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
</dataSources>
</version>
</oracle.manageddataaccess.client>
</configuration>
33 changes: 33 additions & 0 deletions src/DapperDal/Attributes/FieldAtrribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Reflection;

namespace DapperDal.Attributes
{
/// <summary>
/// 字段属性,注解
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class FieldAtrribute:Attribute
{
/// <summary>
/// 是主键 ?
/// </summary>
public bool IsPrimaryKey { get; set; }


/// <summary>
/// 名字
/// </summary>
public string Name { get; set; }



/// <summary>
/// 描述
/// </summary>
public string Describtion { get; set; }
}
}
101 changes: 96 additions & 5 deletions src/DapperDal/DalBaseOfTEntity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using System;
using System.Configuration;
using System.Data;

using System.Data.SqlClient;
//using System.Data.OracleClient;
using Oracle.ManagedDataAccess.Client;

using DapperDal.Mapper;
using DapperDal.Sql;
using DapperDal.Providers;

namespace DapperDal
{
Expand Down Expand Up @@ -47,6 +53,7 @@ static DalBase()
/// </summary>
public DalBase() : this("Default")
{

}

/// <summary>
Expand All @@ -58,11 +65,16 @@ public DalBase() : this("Default")
public DalBase(string connNameOrConnStr)
{
Configuration = DalConfiguration.Default;

// ��ʼ��������
SetDefaultOptions();

ConnectionString = ResolveConnectionString(connNameOrConnStr);
//ConnectionString = ResolveConnectionString(connNameOrConnStr);

ConnectionStringSettings connectionStringSettings = ResolveConnectionStringFromConfig("DapperDalConnStr");

DbType = connectionStringSettings.ProviderName.IndexOf("Oracle") > 0 ?"Oracle":"";
ConnectionString = connectionStringSettings.ConnectionString;
}

/// <summary>
Expand All @@ -80,13 +92,69 @@ public DalBase(string connNameOrConnStr)
/// </summary>
public string ConnectionString { get; private set; }

/// <summary>
/// ���ݿ����� Oracle, SqlServer
/// </summary>
public string DbType { get; set; }

/// <summary>
/// ��DB����
/// </summary>
/// <returns>DB����</returns>
protected virtual IDbConnection OpenConnection()
{
return OpenConnection(ConnectionString);
return OpenConnection(DbType, ConnectionString);
//return OpenConnection(ConnectionString);
}

/// <summary>
/// �������ݿ��ṩ��������
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private static IDbProvider GetProvider(string type)
{
switch (type)
{
case "Oracle":
return new OracleProvider();

case "SqlServer":
default:
return new SqlServerProvider();
}
}

/// <summary>
///
/// </summary>
/// <param name="dbType"></param>
/// <param name="connNameOrConnStr"></param>
/// <returns></returns>
protected virtual IDbConnection OpenConnection(string dbType,string connNameOrConnStr)
{
//var connectionString = ResolveConnectionString(connNameOrConnStr);
//if (string.IsNullOrEmpty(connectionString))
//{
// throw new ArgumentNullException("connectionString");
//}

//------------------------����Ӧ�����������ݿ�����-------------------
IDbProvider dbProvider = GetProvider(dbType);
var connection = dbProvider.CreateConnection();

try
{
connection.ConnectionString = connNameOrConnStr;
}
catch(Exception)
{
throw new ConfigurationErrorsException(string.Format("Failed to create a connection using the connection string '{0}'", connNameOrConnStr));
}

connection.Open();

return connection;
}

/// <summary>
Expand All @@ -102,7 +170,10 @@ protected virtual IDbConnection OpenConnection(string connNameOrConnStr)
throw new ArgumentNullException("connectionString");
}

var connection = new SqlConnection(connectionString);
//------------------------����Ӧ�����������ݿ�����-------------------
//var connection = new SqlConnection(connectionString);
//var connection = new OracleConnection(connectionString);
var connection = new OracleConnection(connectionString);
if (connection == null)
throw new ConfigurationErrorsException(
string.Format("Failed to create a connection using the connection string '{0}'.", connectionString));
Expand All @@ -121,7 +192,11 @@ private static void SetDefaultConfiguration()
{
DalConfiguration.Default.DefaultMapper = typeof(AutoEntityMapper<>);
DalConfiguration.Default.Nolock = true;
DalConfiguration.Default.Buffered = true;
DalConfiguration.Default.Buffered = true;//Ĭ����true,Ҳ�������û���,��Ϊ��ѯ����ʱ�����£����Խ���

//------------------�Զ��� jiftle -----------------------
//DalConfiguration.Default.Buffered = false;
DalConfiguration.Default.Dialect = new OracleDialect();
}
}

Expand Down Expand Up @@ -168,5 +243,21 @@ private string ResolveConnectionString(string connNameOrConnStr)
}
}

/// <summary>
/// �������ļ��л�ȡ���ݿ������ַ���
/// </summary>
/// <returns></returns>
private ConnectionStringSettings ResolveConnectionStringFromConfig(string ConnName)
{
var conStr = ConfigurationManager.ConnectionStrings[ConnName];
if (conStr == null)
{
throw new ConfigurationErrorsException(
string.Format("Failed to find connection string named '{0}' in app/web.config.", ConnName));
}

return conStr;
}

}
}
40 changes: 38 additions & 2 deletions src/DapperDal/DapperDal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,43 @@
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\DapperDal.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\DapperDal.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DocumentationFile>bin\Release\DapperDal.xml</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Dapper, Version=1.50.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Dapper.1.50.2\lib\net40\Dapper.dll</HintPath>
<HintPath>..\..\..\..\coding_net\anbao\code\1.前置服务\ScWCFService\packages\Dapper.1.50.2\lib\net40\Dapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\..\..\coding_net\anbao\code\1.前置服务\ScWCFService\packages\NLog.4.4.12\lib\net40\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=MSIL">
<HintPath>..\..\..\..\coding_net\anbao\code\1.前置服务\ScWCFService\packages\Oracle.ManagedDataAccess.12.2.1100\lib\net40\Oracle.ManagedDataAccess.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.OracleClient" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -46,6 +76,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes\FieldAtrribute.cs" />
<Compile Include="DalBaseOfTEntity.Execute.OtherConn.cs" />
<Compile Include="DalBaseOfTEntity.ExecuteScalar.OtherConn.cs" />
<Compile Include="DalBaseOfTEntity.QueryDataSet.OtherConn.cs" />
Expand Down Expand Up @@ -75,6 +106,11 @@
<Compile Include="DalOptions.cs" />
<Compile Include="DalConfiguration.cs" />
<Compile Include="Expressions\PredicateExtensions.cs" />
<Compile Include="Providers\Common\ConnectionFactory.cs" />
<Compile Include="Providers\IDbProvider.cs" />
<Compile Include="Providers\OracleProvider.cs" />
<Compile Include="Providers\SqlServerProvider.cs" />
<Compile Include="Sql\OracleDialect.cs" />
<Compile Include="Utils\ExpressionExtensions.cs" />
<Compile Include="Expressions\ExpressionUtility.cs" />
<Compile Include="Expressions\PredicateBuilder.cs" />
Expand All @@ -98,9 +134,9 @@
<Compile Include="Sql\SqlServerDialect.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Loading