mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Add unit test
This commit is contained in:
parent
f33658ac6b
commit
f1d50bd15c
@ -97,6 +97,9 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UnitOneToOne12.cs" />
|
||||
<Compile Include="UnitTest\Models\poetry_video_comment.cs" />
|
||||
<Compile Include="UnitTest\Models\user_name_simple.cs" />
|
||||
<Compile Include="UnitTest\UnitInsertNav3.cs" />
|
||||
<Compile Include="UnitTest\UnitInsertNav2.cs" />
|
||||
<Compile Include="UnitTest\UnitInsertNav.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitOneToOne12.Init();
|
||||
UnitInsertNav3.Init();
|
||||
UnitInsertNav2.Init();
|
||||
UnitInsertNav.Init();
|
||||
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
|
||||
namespace SqlSugarDemo
|
||||
{
|
||||
///<summary>
|
||||
///
|
||||
///</summary>
|
||||
[SugarTable("poetry_video_comment")]
|
||||
public partial class poetry_video_comment
|
||||
{
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[Navigate(NavigateType.OneToOne, nameof(user_id))]
|
||||
public user_name_simple CommentUser { set; get; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[Navigate(NavigateType.OneToOne, nameof(reply_user_id))]
|
||||
public user_name_simple ReplyUser { set; get; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[Navigate(NavigateType.OneToOne, nameof(first_reply_id))]
|
||||
public poetry_video_comment FirstReply { set; get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int user_id { get; set; }
|
||||
|
||||
public long? first_reply_id { set; get; }
|
||||
/// <summary>
|
||||
/// Desc:
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public int reply_user_id { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using SqlSugar;
|
||||
namespace SqlSugarDemo
|
||||
{
|
||||
|
||||
[SugarTable("user_name_simple")]
|
||||
public class user_name_simple
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
|
||||
public int id { set; get; }
|
||||
public string name { set; get; }
|
||||
public DateTime create_time { set; get; }
|
||||
}
|
||||
|
||||
|
||||
}
|
52
Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOne12.cs
Normal file
52
Src/Asp.Net/SqlServerTest/UnitTest/UnitOneToOne12.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using SqlSugarDemo;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class UnitOneToOne12
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<user_name_simple, poetry_video_comment>();
|
||||
db.DbMaintenance.TruncateTable<user_name_simple, poetry_video_comment>();
|
||||
var userid = db.Insertable(new user_name_simple()
|
||||
{
|
||||
name = "jack",
|
||||
create_time = DateTime.Now
|
||||
}).ExecuteReturnIdentity();
|
||||
var userid2 = db.Insertable(new user_name_simple()
|
||||
{
|
||||
name = "hellid",
|
||||
create_time = DateTime.Now
|
||||
}).ExecuteReturnIdentity();
|
||||
db.Insertable(new poetry_video_comment()
|
||||
{
|
||||
first_reply_id = 1,
|
||||
reply_user_id = userid2,
|
||||
user_id = userid2
|
||||
}).ExecuteReturnIdentity();
|
||||
db.Insertable(new poetry_video_comment()
|
||||
{
|
||||
first_reply_id = 1,
|
||||
reply_user_id = userid,
|
||||
user_id = userid2
|
||||
}).ExecuteReturnIdentity();
|
||||
db.Insertable(new poetry_video_comment()
|
||||
{
|
||||
first_reply_id = 11,
|
||||
reply_user_id = 11,
|
||||
user_id = 11
|
||||
}).ExecuteReturnIdentity();
|
||||
var list = db.Queryable<poetry_video_comment>()
|
||||
.Includes(o => o.FirstReply, o => o.ReplyUser)
|
||||
.Includes(o => o.FirstReply, o => o.CommentUser)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user