2023-09-08 15:21:31 +08:00
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace OrmTest
|
|
|
|
|
{
|
|
|
|
|
internal class UnitOneToOneDel
|
|
|
|
|
{
|
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
|
|
|
|
var Db = new SqlSugarScope(new ConnectionConfig()
|
|
|
|
|
{
|
|
|
|
|
DbType = DbType.SqlServer,
|
|
|
|
|
ConnectionString = Config.ConnectionString,
|
|
|
|
|
IsAutoCloseConnection = true
|
|
|
|
|
});
|
|
|
|
|
Db.CodeFirst.InitTables<School, Grade>();
|
|
|
|
|
Db.DbMaintenance.TruncateTable<School, Grade>();
|
|
|
|
|
Db.Insertable(new School()
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Name = "a"
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
Db.Insertable(new Grade()
|
|
|
|
|
{
|
|
|
|
|
Name= "b",
|
|
|
|
|
SchoolId=1,
|
|
|
|
|
}).ExecuteCommand();
|
2023-09-08 15:37:53 +08:00
|
|
|
|
Db.DeleteNav<School>(s => s.Id.Equals(1))
|
2023-09-08 15:21:31 +08:00
|
|
|
|
.Include(s => s.Grades).ExecuteCommandAsync().GetAwaiter().GetResult();
|
2023-09-10 01:18:47 +08:00
|
|
|
|
//Console.ReadLine();
|
2023-09-08 15:21:31 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SugarTable("unitSchooldfadsaa")]
|
|
|
|
|
|
|
|
|
|
public class School
|
|
|
|
|
{
|
|
|
|
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
public string? Name { get; set; }
|
2023-09-08 15:37:53 +08:00
|
|
|
|
[Navigate(NavigateType.OneToOne, nameof(Id), nameof(Grade.SchoolId))]
|
2023-09-08 15:21:31 +08:00
|
|
|
|
public Grade Grades { get; set; }
|
|
|
|
|
}
|
|
|
|
|
[SugarTable("unitGradedfadsaa")]
|
|
|
|
|
public class Grade
|
|
|
|
|
{
|
|
|
|
|
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
public string? Name { get; set; }
|
|
|
|
|
public int SchoolId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|