pgsql16,设置了导航属性,但是查不出来子表记录 返回

SqlSugar 沟通中
1 142
该叫什么 北斗 发布于1周前
悬赏:0 飞吻

pgsql16,设置了导航属性,

[SugarTable("ExamSession")]public class ExamSessionEntity: BaseEntity{
    [SugarColumn(IsNullable = true)]    public int? StudentId { get; set; }
    [SugarColumn(IsNullable =true)]    public DateTime? StartTime { get; set; }
    [SugarColumn(IsNullable = true)]    public DateTime? EndTime { get; set; }    /// <summary>
    /// 主从导航:一对多,指向子表的外键字段
    /// </summary>
    [Navigate(NavigateType.OneToMany, nameof(ExamRecordEntity.SessionId))]
    [SugarColumn(IsIgnore = true)]    public List<ExamRecordEntity> Measurements { get; set; } }
    
    
[SugarTable("ExamRecord")]    public class ExamRecordEntity : BaseEntity{    //[Navigate(NavigateType.ManyToOne, nameof(SessionId),nameof(ExamSessionEntity.Id))]
    //[SugarColumn(IsIgnore = true)]
    //public ExamSessionEntity Session { get; set; }
    /// <summary>
    ///// 场次Id
    /// </summary>
    public int SessionId { get; set; }

但是查不出来子表记录

var sessionEntity2 = _db.Queryable<ExamSessionEntity>()
    .Includes(s => s.Measurements)
    .Where(s => s.CommitTime != null && s.StartTime==null && s.CreateBy == userId).OrderBy(s => s.CommitTime);
var sql = sessionEntity2.ToSqlString();
var sessionEntity = sessionEntity2.First();

sql:
SELECT "studentid","starttime","endtime","totalscore","result","committime","id","createdat","modifyat","createby","modifyby" FROM "examsession"  WHERE ((( "committime" IS NOT NULL ) AND ( "starttime" IS NULL )) AND ( "createby" = 2 ))ORDER BY "committime" ASC


热忱回答1

  • 看文档:提问模版,按模版构造测试,有问题提供重现的DEMO

    0 回复