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
e4926ff38a
commit
378ef5ab20
@ -97,6 +97,7 @@
|
||||
<Compile Include="Models\OrderItem.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Models\ViewOrder.cs" />
|
||||
<Compile Include="UnitTest\UnitDynamicaaa.cs" />
|
||||
<Compile Include="UnitTest\UnitBizDel.cs" />
|
||||
<Compile Include="UnitTest\Models\001\InsuranceSectionConfig.cs" />
|
||||
<Compile Include="UnitTest\Models\001\ShouJi.cs" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
using SqlSugar;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitDynamicaaa.Init();
|
||||
UnitBizDel.Init();
|
||||
UnitFilterUpdate.Init();
|
||||
Unitadf1131.Init();
|
||||
|
72
Src/Asp.Net/SqlServerTest/UnitTest/UnitDynamicaaa.cs
Normal file
72
Src/Asp.Net/SqlServerTest/UnitTest/UnitDynamicaaa.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest
|
||||
{
|
||||
public class UnitDynamicaaa
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables<UnitPerson011, UnitAddress011>();
|
||||
db.DbMaintenance.TruncateTable<UnitPerson011, UnitAddress011>();
|
||||
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
AddData(db, "a"+i,"name"+i);
|
||||
}
|
||||
|
||||
var list = db.Queryable<UnitAddress011>()
|
||||
.Includes(x =>
|
||||
x.Persons.MappingField(y => y.AddressId, () => x.Id).ToList()//可以多字段匹配 MappingField(..).MappingField(..).Tolist()
|
||||
).ToList();
|
||||
if (list[150].Persons.Count() != 2)
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddData(SqlSugarClient db,string street,string name)
|
||||
{
|
||||
var address = new UnitAddress011
|
||||
{
|
||||
Street = street
|
||||
};
|
||||
int addressId = db.Insertable(address).ExecuteReturnIdentity();
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
// 创建 UnitPerson011 对象并插入记录
|
||||
var person = new UnitPerson011
|
||||
{
|
||||
Name = name,
|
||||
AddressId = addressId
|
||||
};
|
||||
int personId = db.Insertable(person).ExecuteReturnIdentity();
|
||||
}
|
||||
}
|
||||
}
|
||||
[SugarTable("UnitPerson011xxx")]
|
||||
public class UnitPerson011
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int AddressId { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToOne, nameof(AddressId))]
|
||||
public UnitAddress011 Address { get; set; }
|
||||
}
|
||||
[SugarTable("UnitAddress011sss")]
|
||||
public class UnitAddress011
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
public string Street { get; set; }
|
||||
[SqlSugar.Navigate(SqlSugar.NavigateType.Dynamic, null)]
|
||||
public List<UnitPerson011> Persons { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user