mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add unit test
This commit is contained in:
parent
10905e4494
commit
70be7db6c4
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
Unitasf1.Init();
|
||||
UOneManyMany7.init();
|
||||
UOneManyMany6.init();
|
||||
UinitCustomConvert.Init();
|
||||
|
65
Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitasf1/Unitasf1.cs
Normal file
65
Src/Asp.NetCore2/SqlSeverTest/UnitTest/Unitasf1/Unitasf1.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class Unitasf1
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
|
||||
|
||||
var db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
|
||||
{
|
||||
ConnectionString = "server=.;uid=sa;pwd=sasa;database=sqlsugartestxxxx",
|
||||
DbType = DbType.SqlServer,
|
||||
IsAutoCloseConnection = true
|
||||
}, db =>
|
||||
{
|
||||
|
||||
//如果是多库看标题6
|
||||
|
||||
//每次Sql执行前事件
|
||||
db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
{
|
||||
//我可以在这里面写逻辑
|
||||
|
||||
//技巧:AOP中获取IOC对象
|
||||
//var serviceBuilder = services.BuildServiceProvider();
|
||||
//var log= serviceBuilder.GetService<ILogger<WeatherForecastController>>();
|
||||
|
||||
|
||||
//获取原生SQL推荐 5.1.4.63 性能OK
|
||||
Console.WriteLine(UtilMethods.GetNativeSql(sql, pars));
|
||||
};
|
||||
|
||||
});
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
//建表
|
||||
if (!db.DbMaintenance.IsAnyTable("app_category", false)) { db.CodeFirst.InitTables<entity.app_category>(); }
|
||||
if (!db.DbMaintenance.IsAnyTable("app_comment", false)) { db.CodeFirst.InitTables<entity.app_comment>(); }
|
||||
if (!db.DbMaintenance.IsAnyTable("app_revision", false)) { db.CodeFirst.InitTables<entity.app_revision>(); }
|
||||
if (!db.DbMaintenance.IsAnyTable("app_topic", false)) { db.CodeFirst.InitTables<entity.app_topic>(); }
|
||||
|
||||
|
||||
//用例代码
|
||||
//var result = db.Insertable(new Test001() { id = 1 }).ExecuteCommand();//用例代码
|
||||
|
||||
var _query = db.Queryable <entityMap.app_topic>();
|
||||
//_query.Includes(k => k.map_app_category);
|
||||
//_query.Includes(k => k.map_app_revision);
|
||||
//_query.Includes(k => k.map_app_comment);
|
||||
var _queryPagerSelect = _query.Select(k => new entityMapDTO.app_topic()
|
||||
{
|
||||
fk_category_name = k.map_app_category.category_name,
|
||||
fk_comment_total = k.map_app_comment.Count(),
|
||||
IsAny = k.map_app_revision.Any(),
|
||||
},true)
|
||||
.ToList() ;
|
||||
//Console.WriteLine("用例跑完");
|
||||
//Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest.entity
|
||||
{
|
||||
///<summary>
|
||||
/// 分类
|
||||
///</summary>
|
||||
//[Tenant(nameof(enumTenant.app))]
|
||||
[SugarTable("app_category")]
|
||||
public partial class app_category
|
||||
{
|
||||
public app_category(){
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:分类编号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
|
||||
public long category_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:上级分类编号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public long? category_pid {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:分类名称
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string category_name {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:版本号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true)]//标识版本字段
|
||||
public Guid? ver {get;set;}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest.entity
|
||||
{
|
||||
///<summary>
|
||||
///评论
|
||||
///</summary>
|
||||
//[Tenant(nameof(enumTenant.app))]
|
||||
[SugarTable("app_comment")]
|
||||
public partial class app_comment
|
||||
{
|
||||
public app_comment(){
|
||||
|
||||
this.topic_id =Convert.ToInt64("0");
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:评论编号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
|
||||
public long comment_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:主题编号
|
||||
/// Default:0
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public long? topic_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:评论内容
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string content {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:版本号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true)]//标识版本字段
|
||||
public Guid? ver {get;set;}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest.entity
|
||||
{
|
||||
///<summary>
|
||||
///修订记录
|
||||
///</summary>
|
||||
//[Tenant(nameof(enumTenant.app))]
|
||||
[SugarTable("app_revision")]
|
||||
public partial class app_revision
|
||||
{
|
||||
public app_revision(){
|
||||
|
||||
this.topic_id =Convert.ToInt64("0");
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:修订编号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
|
||||
public long revision_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:主题编号
|
||||
/// Default:0
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public long? topic_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:版本号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true)]//标识版本字段
|
||||
public Guid? ver {get;set;}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest.entity
|
||||
{
|
||||
///<summary>
|
||||
///主题
|
||||
///</summary>
|
||||
//[Tenant(nameof(enumTenant.app))]
|
||||
[SugarTable("app_topic")]
|
||||
public partial class app_topic
|
||||
{
|
||||
public app_topic(){
|
||||
|
||||
this.category_id =Convert.ToInt64("0");
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Desc:编号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey=true,IsIdentity=true)]
|
||||
public long topic_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:分类编号
|
||||
/// Default:0
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public long? category_id {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:主题
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string title {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:版本号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
[SqlSugar.SugarColumn(IsEnableUpdateVersionValidation = true)]//标识版本字段
|
||||
public Guid? ver {get;set;}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest.entityMap
|
||||
{
|
||||
public class app_topic : entity.app_topic
|
||||
{
|
||||
/// <summary>
|
||||
/// 导航表:分类
|
||||
/// </summary>
|
||||
[Navigate(NavigateType.OneToOne, nameof(category_id))]
|
||||
public entity.app_category map_app_category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 导航表:评论
|
||||
/// </summary>
|
||||
[Navigate(NavigateType.OneToMany, nameof(entity.app_topic.topic_id), nameof(entity.app_comment.topic_id))]
|
||||
public List<entity.app_comment> map_app_comment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 导航表:版本
|
||||
/// </summary>
|
||||
[Navigate(NavigateType.OneToMany, nameof(entity.app_topic.topic_id), nameof(entity.app_revision.topic_id))]
|
||||
public List<entity.app_revision> map_app_revision { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.entityMapDTO
|
||||
{
|
||||
public class app_topic : entity.app_topic
|
||||
{
|
||||
/// <summary>
|
||||
/// 分类名称
|
||||
/// <para>映射至:<seealso cref="entity.app_category.category_name"/></para>
|
||||
/// </summary>
|
||||
public string fk_category_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 评论数量
|
||||
/// <para>映射至:<seealso cref="entity.app_comment.comment_id"/></para>
|
||||
/// </summary>
|
||||
public Int64 fk_comment_total { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 版本数量
|
||||
/// <para>映射至:<seealso cref="entity.app_revision.revision_id"/></para>
|
||||
/// </summary>
|
||||
public Int64 fk_revision_total { get; set; } = 0;
|
||||
public bool IsAny { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user