mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-02 20:02:47 +08:00
4.5.1.8
This commit is contained in:
parent
9aa6794f7a
commit
8b3400320f
@ -1,10 +1,8 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data.SQLite;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
@ -19,34 +17,35 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings =JsonConvert.DefaultSettings;
|
||||
Assembly asmb = Assembly.LoadFrom("Newtonsoft.Json.dll");
|
||||
asmb = CheckAssembly(asmb);
|
||||
IsTryJsonNet = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
var message= ErrorMessage.GetThrowMessage(
|
||||
" Some functions are used in newtonsoft ,Nuget references newtonsoft.json, 9.0.0.1 + ."+ex.Message,
|
||||
" 部分功能用到newtonsoft,Nuget上面下载安装 newtonsoft.json, 9.0.0.1及以上版本,如果有版本兼容问题请先删除原有引用,详细错误:"+ex.Message);
|
||||
Check.ThrowNotSupportedException(message);
|
||||
var message = ErrorMessage.GetThrowMessage(
|
||||
" Some functions are used in newtonsoft ,Nuget references Newtonsoft.Json 9.0.0.1 + .",
|
||||
" 部分功能用到Newtonsoft.Json.dll,需要在Nuget上安装 Newtonsoft.Json 9.0.0.1及以上版本,如果有版本兼容问题请先删除原有引用");
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryMySqlData()
|
||||
{
|
||||
if (!IsTryMySqlData)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (MySqlConnection mySql = new MySqlConnection()){}
|
||||
Assembly asmb = Assembly.LoadFrom("MySql.Data.dll");
|
||||
asmb = CheckAssembly(asmb);
|
||||
IsTryMySqlData = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
var message = ErrorMessage.GetThrowMessage(
|
||||
"You need to refer to MySql.Data.dll"+ex.Message,
|
||||
"需要MySql.Data.dll请在Nuget安装最新版本,如果有版本兼容问题请先删除原有引用,详细错误:" + ex.Message);
|
||||
Check.ThrowNotSupportedException(message);
|
||||
"You need to refer to MySql.Data.dll" ,
|
||||
"需要引用MySql.Data.dll,请在Nuget安装最新稳定版本,如果有版本兼容问题请先删除原有引用");
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,17 +56,26 @@ namespace SqlSugar
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SQLiteConnection mySql = new SQLiteConnection()) { }
|
||||
Assembly asmb = Assembly.LoadFrom("System.Data.SQLite.dll");
|
||||
asmb = CheckAssembly(asmb);
|
||||
IsTrySqlite = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var message = ErrorMessage.GetThrowMessage(
|
||||
ex.Message,
|
||||
"需要Sqlite相关的驱动,如果有版本兼容问题请先删除原有引用,如果有版本兼容问题请先删除原有引用,详细错误:" + ex.Message);
|
||||
Check.ThrowNotSupportedException(message);
|
||||
"You need to refer to System.Data.SQLite.dll",
|
||||
"你需要引用System.Data.SQLite.dll,如果有版本兼容问题请先删除原有引用");
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Assembly CheckAssembly(Assembly asmb)
|
||||
{
|
||||
if (asmb == null) throw new Exception("");
|
||||
asmb = null;
|
||||
return asmb;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ namespace SqlSugar
|
||||
var result = (Restult)Activator.CreateInstance(type, true);
|
||||
return result;
|
||||
}
|
||||
private static T CreateInstance<T>(string className)
|
||||
public static T CreateInstance<T>(string className)
|
||||
{
|
||||
Type type;
|
||||
if (typeCache.ContainsKey(className))
|
||||
|
@ -6,7 +6,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class RewritableMethods : IRewritableMethods
|
||||
@ -192,9 +191,11 @@ namespace SqlSugar
|
||||
public string SerializeObject(object value)
|
||||
{
|
||||
DependencyManagement.TryJsonNet();
|
||||
return JsonConvert.SerializeObject(value);
|
||||
return JsonHelper.SerializeObject(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Serialize Object
|
||||
/// </summary>
|
||||
@ -203,8 +204,7 @@ namespace SqlSugar
|
||||
public T DeserializeObject<T>(string value)
|
||||
{
|
||||
DependencyManagement.TryJsonNet();
|
||||
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
||||
return JsonHelper.DeserializeObject<T>(value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -257,7 +257,7 @@ namespace SqlSugar
|
||||
}
|
||||
deserializeObject.Add(childRow);
|
||||
}
|
||||
return JsonConvert.DeserializeObject<dynamic>(JsonConvert.SerializeObject(deserializeObject));
|
||||
return this.DeserializeObject<dynamic>(this.SerializeObject(deserializeObject));
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("4.5.1.7")]
|
||||
[assembly: AssemblyFileVersion("4.5.1.7")]
|
||||
[assembly: AssemblyVersion("4.5.1.8")]
|
||||
[assembly: AssemblyFileVersion("4.5.1.8")]
|
||||
|
@ -73,6 +73,7 @@
|
||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||
<Compile Include="Enum\DbType.cs" />
|
||||
<Compile Include="Infrastructure\DependencyManagement.cs" />
|
||||
<Compile Include="Utilities\JsonHelper.cs" />
|
||||
<Compile Include="Utilities\ReflectionExtensions.cs" />
|
||||
<Compile Include="Realization\MySql\CodeFirst\MySqlCodeFirst.cs" />
|
||||
<Compile Include="Realization\MySql\DbFirst\MySqlDbFirst.cs" />
|
||||
|
@ -22,6 +22,7 @@ namespace SqlSugar
|
||||
{
|
||||
base.Context = this;
|
||||
base.CurrentConnectionConfig = config;
|
||||
Check.ArgumentNullException(config, "config is null");
|
||||
switch (config.DbType)
|
||||
{
|
||||
case DbType.MySql:
|
||||
@ -33,9 +34,9 @@ namespace SqlSugar
|
||||
DependencyManagement.TrySqlite();
|
||||
break;
|
||||
case DbType.Oracle:
|
||||
throw new Exception("Oracle developed 60%,to be continued ");
|
||||
throw new Exception("Oracle developed 60%,to be continued");
|
||||
default:
|
||||
break;
|
||||
throw new Exception("ConnectionConfig.DbType is null");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -71,7 +71,8 @@ namespace SqlSugar
|
||||
{
|
||||
List<string> formatArgs = new List<string>() { enMessage, cnMessage };
|
||||
formatArgs.AddRange(args);
|
||||
return string.Format("\r\n English Message : {0}\r\n Chinese Message : {1}", formatArgs.ToArray());
|
||||
return string.Format(@"English Message : {0}
|
||||
Chinese Message : {1}", formatArgs.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
Src/Asp.Net/SqlSugar/Utilities/JsonHelper.cs
Normal file
22
Src/Asp.Net/SqlSugar/Utilities/JsonHelper.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class JsonHelper
|
||||
{
|
||||
public static string SerializeObject(object value)
|
||||
{
|
||||
return JsonConvert.SerializeObject(value);
|
||||
}
|
||||
|
||||
public static T DeserializeObject<T>(string value)
|
||||
{
|
||||
var jSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
return JsonConvert.DeserializeObject<T>(value, jSetting);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user