mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-05 17:37:58 +08:00
Add unit test
This commit is contained in:
parent
5e9ea147ff
commit
263e9b6091
@ -31,6 +31,7 @@ namespace OrmTest
|
|||||||
}
|
}
|
||||||
public static void Init()
|
public static void Init()
|
||||||
{
|
{
|
||||||
|
UnitOneToMany2.Init();
|
||||||
UnitOneToMany.Init();
|
UnitOneToMany.Init();
|
||||||
UnitOneToOneDel.Init();
|
UnitOneToOneDel.Init();
|
||||||
EntityInfoTest.Init();
|
EntityInfoTest.Init();
|
||||||
|
71
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UnitOneToMany2.cs
Normal file
71
Src/Asp.NetCore2/SqlSeverTest/UnitTest/UnitOneToMany2.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
internal class UnitOneToMany2
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
var db = NewUnitTest.Db;
|
||||||
|
db.CodeFirst.InitTables<UnitPerson011, UnitAddress011, UnitCity>();
|
||||||
|
db.DbMaintenance.TruncateTable<UnitPerson011, UnitAddress011, UnitCity>();
|
||||||
|
|
||||||
|
var address = new UnitAddress011
|
||||||
|
{
|
||||||
|
Street = "123 Main Street",
|
||||||
|
CityId=1,Persons=new List<UnitPerson011>() {
|
||||||
|
new UnitPerson011
|
||||||
|
{
|
||||||
|
Name = "John Doe"
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
City=new UnitCity() {
|
||||||
|
AddressId=1,
|
||||||
|
Name="city"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
db.InsertNav(address)
|
||||||
|
.IncludeByNameString("Persons")
|
||||||
|
.IncludeByNameString("City").ExecuteCommand();
|
||||||
|
|
||||||
|
var list = db.Queryable<UnitAddress011>().Includes(x => x.Persons).Includes(x => x.City).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
[SqlSugar.SugarTable("UnitPerson01x1")]
|
||||||
|
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.SugarTable("UnitCityaa")]
|
||||||
|
public class UnitCity
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int AddressId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[SqlSugar.SugarTable("UnitAddressx011")]
|
||||||
|
public class UnitAddress011
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Street { get; set; }
|
||||||
|
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToMany, nameof(UnitPerson011.AddressId))]
|
||||||
|
public List<UnitPerson011> Persons { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsNullable =true)]
|
||||||
|
public int CityId { get; set; }
|
||||||
|
[SqlSugar.Navigate(SqlSugar.NavigateType.OneToOne, nameof(CityId))]
|
||||||
|
public UnitCity City { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user