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
f9842df490
commit
b6edcde506
@ -126,6 +126,7 @@
|
||||
<Compile Include="UnitTest\UExp.cs" />
|
||||
<Compile Include="UnitTest\UCustom24.cs" />
|
||||
<Compile Include="UnitTest\UCustom20.cs" />
|
||||
<Compile Include="UnitTest\UnitUpdateOneToMany.cs" />
|
||||
<Compile Include="UnitTest\UnitUpdateSubQuery.cs" />
|
||||
<Compile Include="UnitTest\UnitManyToManyDeleteNav.cs" />
|
||||
<Compile Include="UnitTest\UnitCustom12312.cs" />
|
||||
|
84
Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany.cs
Normal file
84
Src/Asp.Net/SqlServerTest/UnitTest/UnitUpdateOneToMany.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using SqlSugar;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UnitUpdateOneToMany
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
//建表
|
||||
db.CodeFirst.InitTables<Country, Province>();
|
||||
db.DbMaintenance.TruncateTable<Country, Province>();
|
||||
|
||||
//插入一级导航数据
|
||||
var country = new Country
|
||||
{
|
||||
Id = 1,
|
||||
Name= "Test",
|
||||
Provinces = new List<Province> {
|
||||
new Province{
|
||||
Id = 1,
|
||||
CountryId = 1,
|
||||
IsDeleted= false,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
db.QueryFilter.AddTableFilter<Province>(it => it.IsDeleted == false);
|
||||
//用例代码
|
||||
var result = db.InsertNav(country)
|
||||
.Include(it => it.Provinces)
|
||||
.ExecuteCommand();//用例代码
|
||||
|
||||
var list2 = db.Queryable<Country>().Includes(x => x.Provinces).ToList();
|
||||
country = new Country
|
||||
{
|
||||
Id = 1,
|
||||
Name = "中国",
|
||||
Provinces = new List<Province> {
|
||||
new Province{
|
||||
Id = 2,
|
||||
CountryId = 1,
|
||||
IsDeleted= false,
|
||||
},
|
||||
}
|
||||
};
|
||||
//用例代码
|
||||
db.UpdateNav(country)
|
||||
.Include(it => it.Provinces,new UpdateNavOptions() { OneToManyEnableLogicDelete=true })
|
||||
.ExecuteCommand();//
|
||||
|
||||
var list3=db.Queryable<Country>().Includes(x => x.Provinces).ToList();
|
||||
db.QueryFilter.Clear<Province>();
|
||||
var list4 = db.Queryable<Country>().Includes(x => x.Provinces).ToList();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//建类
|
||||
[SugarTable("Unitaaa1Countradsfay")]
|
||||
public class Country
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
[Navigate(NavigateType.OneToMany, nameof(Province.CountryId))]
|
||||
public List<Province> Provinces { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
[SugarTable("Unitaaa1Proviasdfance")]
|
||||
public class Province
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
public long CountryId { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user