From a8bf2590a565f3392fa46a7526a0145f5961456a Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 24 Oct 2022 12:50:28 +0800 Subject: [PATCH] Add unit test --- Src/Asp.Net/SqliteTest/SqliteTest.csproj | 1 + Src/Asp.Net/SqliteTest/UnitTest/Main.cs | 1 + .../SqliteTest/UnitTest/UnitNavInsertIssue.cs | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 Src/Asp.Net/SqliteTest/UnitTest/UnitNavInsertIssue.cs diff --git a/Src/Asp.Net/SqliteTest/SqliteTest.csproj b/Src/Asp.Net/SqliteTest/SqliteTest.csproj index ade4e030c..94d0449b5 100644 --- a/Src/Asp.Net/SqliteTest/SqliteTest.csproj +++ b/Src/Asp.Net/SqliteTest/SqliteTest.csproj @@ -77,6 +77,7 @@ + diff --git a/Src/Asp.Net/SqliteTest/UnitTest/Main.cs b/Src/Asp.Net/SqliteTest/UnitTest/Main.cs index f1ced768e..178236ef5 100644 --- a/Src/Asp.Net/SqliteTest/UnitTest/Main.cs +++ b/Src/Asp.Net/SqliteTest/UnitTest/Main.cs @@ -31,6 +31,7 @@ namespace OrmTest } public static void Init() { + UnitNavInsertIssue.Init(); UnitInsertNavN.Init(); UNavTest.Init(); UnitTestReturnPkList.Init(); diff --git a/Src/Asp.Net/SqliteTest/UnitTest/UnitNavInsertIssue.cs b/Src/Asp.Net/SqliteTest/UnitTest/UnitNavInsertIssue.cs new file mode 100644 index 000000000..292166743 --- /dev/null +++ b/Src/Asp.Net/SqliteTest/UnitTest/UnitNavInsertIssue.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +namespace OrmTest +{ + + public class UnitNavInsertIssue + { + + public static void Init() + { + ConnectionConfig cfg = new ConnectionConfig() + { + DbType = DbType.MySql, + ConnectionString = "随便填一个本地的吧" + }; + var sqlSugarScope = NewUnitTest.Db; + sqlSugarScope.DbMaintenance.CreateDatabase(); + sqlSugarScope.CodeFirst.InitTables(typeof(Mail), typeof(MailAttachment)); + Mail mail = new Mail() + { + TraceId = "abcd", + Subject = "subject", + Content = "content" + }; + sqlSugarScope + .InsertNav(mail) + .Include(p => p.Attachments) + .ExecuteCommand(); + } + } + + [SugarTable(nameof(Mail))] + public class Mail + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + [SugarColumn(IsNullable = false, Length = 20)] + public string TraceId { get; set; } + [SugarColumn(IsNullable = false, Length = 500)] + public string Subject { get; set; } + [SugarColumn(IsNullable = false, Length = 2000)] + public string Content { get; set; } + [Navigate(NavigateType.OneToMany, nameof(MailAttachment.MailTraceId), nameof(TraceId))] + public List Attachments { get; set; } + } + + [SugarTable(nameof(MailAttachment))] + public class MailAttachment + { + [SugarColumn(IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + [SugarColumn(IsNullable = false, Length = 20)] + public string MailTraceId { get; set; } + [SugarColumn(IsNullable = false, Length = 100)] + public string FileName { get; set; } + } + +}