SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

3 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
public class UCustom021
{
public static void Inti() {
var db = NewUnitTest.Db;
db.CodeFirst.SetStringDefaultLength(20).InitTables<UnitStudent111>();
db.CodeFirst.SetStringDefaultLength(20).InitTables<UnitExam>();
var id = db.Insertable(new UnitStudent111() { Name = "小a" }).ExecuteReturnIdentity();
db.Insertable(new UnitExam
{
StudentId = id,
Number = 1,
Time = DateTime.Now
}).ExecuteCommand();
var result2 = db.Queryable<UnitStudent111>()
3 years ago
.Includes(e => e.Exams.Where(s => s.Time >DateTime.Now).ToList()).ToList();
3 years ago
}
}
public class UnitStudent111
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int Id { get; set; }
public string Name { get; set; }
[Navigate(NavigateType.OneToMany, nameof(UnitExam.StudentId))]//BookA表中的studenId
public List<UnitExam> Exams { get; set; }
}
public class UnitExam
{
[SugarColumn(IsIdentity = true, IsPrimaryKey = true)]
public int Id { get; set; }
public int StudentId { get; set; }
public int Number { get; set; }
public DateTime Time { get; set; }
}
}