- 增加 所有国产数据库支持 CustomMySql、CustomPostgreSQL、CustomOracle、CustomSqlServer 自定义适配;

This commit is contained in:
2881099
2022-09-09 01:38:24 +08:00
parent 3ec8e2118d
commit b7e96620a7
146 changed files with 50828 additions and 29 deletions

View File

@ -0,0 +1,77 @@
using MySqlConnector;
using Npgsql;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Text;
public class g
{
static Lazy<IFreeSql> mysqlLazy = new Lazy<IFreeSql>(() =>
{
var fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.CustomMySql, () => new MySqlConnection("Server=127.0.0.1;Persist Security Info=False;UID=root;PWD=root;DATABASE=cccddd_custom;Charset=utf8;SslMode=none;"))
.UseAutoSyncStructure(true)
.UseMonitorCommand(
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象在执行前
(cmd, traceLog) => Console.WriteLine(traceLog))
.UseLazyLoading(true)
.Build();
fsql.SetDbProviderFactory(MySqlConnectorFactory.Instance);
return fsql;
});
public static IFreeSql mysql => mysqlLazy.Value;
static Lazy<IFreeSql> sqlserverLazy = new Lazy<IFreeSql>(() =>
{
var fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.CustomSqlServer, () => new SqlConnection("Server=.;Persist Security Info=False;Trusted_Connection=Yes;Integrated Security=True;DATABASE=freesqlTest_custom;Pooling=true;"))
.UseAutoSyncStructure(true)
.UseMonitorCommand(
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象在执行前
(cmd, traceLog) => Console.WriteLine(traceLog))
.UseLazyLoading(true)
.Build();
fsql.SetDbProviderFactory(SqlClientFactory.Instance);
return fsql;
});
public static IFreeSql sqlserver => sqlserverLazy.Value;
static Lazy<IFreeSql> oracleLazy = new Lazy<IFreeSql>(() =>
{
var fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.CustomOracle, () => new OracleConnection("user id=1custom;password=123456;data source=//127.0.0.1:1521/XE;Pooling=true;Max Pool Size=2"))
.UseAutoSyncStructure(true)
.UseLazyLoading(true)
.UseNameConvert(FreeSql.Internal.NameConvertType.ToUpper)
//.UseNoneCommandParameter(true)
.UseMonitorCommand(
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象在执行前
(cmd, traceLog) => Console.WriteLine(traceLog))
.Build();
fsql.SetDbProviderFactory(OracleClientFactory.Instance);
return fsql;
});
public static IFreeSql oracle => oracleLazy.Value;
static Lazy<IFreeSql> pgsqlLazy = new Lazy<IFreeSql>(() =>
{
var fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionFactory(FreeSql.DataType.CustomPostgreSQL, () => new NpgsqlConnection("Server=192.168.164.10;Port=5432;UID=postgres;PWD=123456;Database=tedb_custom;Pooling=true;"))
.UseAutoSyncStructure(true)
.UseNameConvert(FreeSql.Internal.NameConvertType.ToLower)
.UseLazyLoading(true)
.UseMonitorCommand(
cmd => Trace.WriteLine(cmd.CommandText), //监听SQL命令对象在执行前
(cmd, traceLog) => Console.WriteLine(traceLog))
.Build();
fsql.SetDbProviderFactory(NpgsqlFactory.Instance);
return fsql;
});
public static IFreeSql pgsql => pgsqlLazy.Value;
}