mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Add unit test
This commit is contained in:
parent
41541bee7e
commit
7282b2581a
@ -99,6 +99,7 @@
|
|||||||
<Compile Include="UnitTest\Models\TestModel.cs" />
|
<Compile Include="UnitTest\Models\TestModel.cs" />
|
||||||
<Compile Include="UnitTest\Models\UserEntity.cs" />
|
<Compile Include="UnitTest\Models\UserEntity.cs" />
|
||||||
<Compile Include="UnitTest\Models\UserRoleEntity.cs" />
|
<Compile Include="UnitTest\Models\UserRoleEntity.cs" />
|
||||||
|
<Compile Include="UnitTest\UCustom015.cs" />
|
||||||
<Compile Include="UnitTest\UCustom014.cs" />
|
<Compile Include="UnitTest\UCustom014.cs" />
|
||||||
<Compile Include="UnitTest\UCustom013.cs" />
|
<Compile Include="UnitTest\UCustom013.cs" />
|
||||||
<Compile Include="UnitTest\UCustom01.cs" />
|
<Compile Include="UnitTest\UCustom01.cs" />
|
||||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
UCustom015.Init();
|
||||||
UCustom014.Init();
|
UCustom014.Init();
|
||||||
UCustom013.Init();
|
UCustom013.Init();
|
||||||
UCustom012.Init();
|
UCustom012.Init();
|
||||||
|
@ -20,9 +20,9 @@ namespace OrmTest
|
|||||||
});
|
});
|
||||||
|
|
||||||
db.CodeFirst.InitTables<Country111, Province111, City111>();
|
db.CodeFirst.InitTables<Country111, Province111, City111>();
|
||||||
db.DbMaintenance.TruncateTable("Country111");
|
db.DbMaintenance.TruncateTable("Country_111");
|
||||||
db.DbMaintenance.TruncateTable("Province111");
|
db.DbMaintenance.TruncateTable("Province_111");
|
||||||
db.DbMaintenance.TruncateTable("City111");
|
db.DbMaintenance.TruncateTable("City_111");
|
||||||
db.Insertable(new List<Country111>()
|
db.Insertable(new List<Country111>()
|
||||||
{
|
{
|
||||||
new Country111(){
|
new Country111(){
|
||||||
|
101
Src/Asp.Net/SqlServerTest/UnitTest/UCustom015.cs
Normal file
101
Src/Asp.Net/SqlServerTest/UnitTest/UCustom015.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class UCustom015
|
||||||
|
{
|
||||||
|
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = new SqlSugarScope(new SqlSugar.ConnectionConfig()
|
||||||
|
{
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
DbType = DbType.SqlServer,
|
||||||
|
IsAutoCloseConnection = true
|
||||||
|
});
|
||||||
|
db.DbMaintenance.CreateDatabase();
|
||||||
|
|
||||||
|
db.CodeFirst.InitTables<Country1111>();
|
||||||
|
db.CodeFirst.InitTables<Province1111>();
|
||||||
|
db.CodeFirst.InitTables<Country111Info>();
|
||||||
|
db.DbMaintenance.TruncateTable("Country_1111");
|
||||||
|
db.DbMaintenance.TruncateTable("Province_1111");
|
||||||
|
db.DbMaintenance.TruncateTable("Country111Info");
|
||||||
|
var c = new Country1111()
|
||||||
|
{
|
||||||
|
Id=1,
|
||||||
|
Name="中国",InfoId=1
|
||||||
|
};
|
||||||
|
var ps = new List<Province1111>(){
|
||||||
|
new Province1111{
|
||||||
|
Id=1001,
|
||||||
|
Name="江苏", CountryId=1
|
||||||
|
|
||||||
|
},
|
||||||
|
new Province1111{
|
||||||
|
Id=1002,
|
||||||
|
Name="上海", CountryId=1
|
||||||
|
|
||||||
|
},
|
||||||
|
new Province1111{
|
||||||
|
Id=1003,
|
||||||
|
Name="北京", CountryId=1
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
db.Insertable(c).ExecuteCommand();
|
||||||
|
db.Insertable(ps).ExecuteCommand();
|
||||||
|
db.Insertable(new Country111Info { Id=1, Name="infoa"}).ExecuteCommand();
|
||||||
|
db.Aop.OnLogExecuted = (sq, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sq);
|
||||||
|
};
|
||||||
|
|
||||||
|
var list = db.Queryable<Country1111>()
|
||||||
|
.Includes(x => x.Info)
|
||||||
|
.ToList();
|
||||||
|
var list2 = db.Queryable<Country1111>()
|
||||||
|
.Includes(x => x.Provinces.OrderByDescending(x111 => x111.Id).ToList())
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SugarTable("Country_1111")]
|
||||||
|
public class Country1111
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true, ColumnName = "cid")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int InfoId { get; set; }
|
||||||
|
|
||||||
|
[Navigat(NavigatType.OneToOne, nameof(InfoId))]
|
||||||
|
public Country111Info Info { get; set; }
|
||||||
|
|
||||||
|
[Navigat(NavigatType.OneToMany,nameof(Province1111.CountryId))]
|
||||||
|
public List<Province1111> Provinces { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Country111Info
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true,ColumnName = "infoId")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[SugarTable("Province_1111")]
|
||||||
|
public class Province1111
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn( ColumnName = "pid")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
[SugarColumn(ColumnName = "coid")]
|
||||||
|
public int CountryId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user