SqlSugar/Src/Asp.NetCore2/MySqlTest/UserTestCases/UnitTest/Unitdfasfasfa.cs
2024-02-05 15:22:29 +08:00

74 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
internal class Unitdfasfasfa
{
public static void Init()
{
ConnectionConfig connectionConfig = new ConnectionConfig()
{
DbType = DbType.MySql,
ConfigId = "Default",
ConnectionString =Config.ConnectionString
};
ConnectionConfig connectionConfig1 = new ConnectionConfig()
{
DbType = DbType.MySql,
ConfigId = "Default1",
ConnectionString = Config.ConnectionString
};
var db = new SqlSugarClient(new List<ConnectionConfig> { connectionConfig, connectionConfig1 },
db =>
{
//调试SQL事件可以删掉 (要放在执行方法之前)
db.Aop.OnLogExecuting = (sql, pars) =>
{
//Console.WriteLine(sql);//输出sql,查看执行sql 性能无影响
};
});
var Db = db.GetConnection("Default");
Console.WriteLine($"Db 的MappingTables 属性为Null {Db.MappingTables == null}");
var Db1 = db.GetConnection("Default1");
Console.WriteLine($"Db1 的MappingTables 属性为Null {Db1.MappingTables == null}");
var type = typeof(TestTable);
Db.CodeFirst.InitTables(type);
Db1.CodeFirst.InitTables(type);
Console.WriteLine("Hello, World!");
var list2 = NewUnitTest.Db.Reportable(new List<Unitguidsda>() {
new Unitguidsda()
}).ToQueryable().ToList();
}
public class Unitguidsda
{
public Guid Id { get; set; } = Guid.NewGuid();
}
[SugarTable("Test_Table_{year}{month}{day}")]
[SplitTable(SplitType.Month)]
public class TestTable
{
[SugarColumn(ColumnDescription = "创建时间", IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnDescription = "创建时间", CreateTableFieldSort = 993, IsOnlyIgnoreUpdate = true)]
[SplitField]
public DateTime CreationTime { get; set; }
}
}
}