diff --git a/src/DapperDal/App.config b/src/DapperDal/App.config new file mode 100644 index 000000000..fb8ed4507 --- /dev/null +++ b/src/DapperDal/App.config @@ -0,0 +1,30 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/DapperDal/Attributes/FieldAtrribute.cs b/src/DapperDal/Attributes/FieldAtrribute.cs new file mode 100644 index 000000000..be9222b80 --- /dev/null +++ b/src/DapperDal/Attributes/FieldAtrribute.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +//using System.Reflection; + +namespace DapperDal.Attributes +{ + /// + /// 字段属性,注解 + /// + [AttributeUsage(AttributeTargets.Property)] + public class FieldAtrribute:Attribute + { + /// + /// 是主键 ? + /// + public bool IsPrimaryKey { get; set; } + + + /// + /// 名字 + /// + public string Name { get; set; } + + + + /// + /// 描述 + /// + public string Describtion { get; set; } + } +} diff --git a/src/DapperDal/DalBaseOfTEntity.cs b/src/DapperDal/DalBaseOfTEntity.cs index cd1721717..9742bed50 100644 --- a/src/DapperDal/DalBaseOfTEntity.cs +++ b/src/DapperDal/DalBaseOfTEntity.cs @@ -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 { @@ -47,6 +53,7 @@ static DalBase() /// public DalBase() : this("Default") { + } /// @@ -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; } /// @@ -80,13 +92,69 @@ public DalBase(string connNameOrConnStr) /// public string ConnectionString { get; private set; } + /// + /// ݿ Oracle, SqlServer + /// + public string DbType { get; set; } + /// /// DB /// /// DB protected virtual IDbConnection OpenConnection() { - return OpenConnection(ConnectionString); + return OpenConnection(DbType, ConnectionString); + //return OpenConnection(ConnectionString); + } + + /// + /// ݿṩ + /// + /// + /// + private static IDbProvider GetProvider(string type) + { + switch (type) + { + case "Oracle": + return new OracleProvider(); + + case "SqlServer": + default: + return new SqlServerProvider(); + } + } + + /// + /// + /// + /// + /// + /// + 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; } /// @@ -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)); @@ -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(); } } @@ -168,5 +243,21 @@ private string ResolveConnectionString(string connNameOrConnStr) } } + /// + /// ļлȡݿַ + /// + /// + 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; + } + } } \ No newline at end of file diff --git a/src/DapperDal/DapperDal.csproj b/src/DapperDal/DapperDal.csproj index 5cec4eaaa..d89adbe64 100644 --- a/src/DapperDal/DapperDal.csproj +++ b/src/DapperDal/DapperDal.csproj @@ -31,13 +31,43 @@ 4 bin\Release\DapperDal.xml + + true + bin\x86\Debug\ + DEBUG;TRACE + bin\Debug\DapperDal.xml + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + TRACE + bin\Release\DapperDal.xml + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + - ..\..\packages\Dapper.1.50.2\lib\net40\Dapper.dll + ..\..\..\..\coding_net\anbao\code\1.前置服务\ScWCFService\packages\Dapper.1.50.2\lib\net40\Dapper.dll + True + + + ..\..\..\..\coding_net\anbao\code\1.前置服务\ScWCFService\packages\NLog.4.4.12\lib\net40\NLog.dll + True + + + ..\..\..\..\coding_net\anbao\code\1.前置服务\ScWCFService\packages\Oracle.ManagedDataAccess.12.2.1100\lib\net40\Oracle.ManagedDataAccess.dll + True + @@ -46,6 +76,7 @@ + @@ -75,6 +106,11 @@ + + + + + @@ -98,9 +134,9 @@ + -