多对多导航插入,在中间表中增加自定义参数 导航插入要怎么查询 返回

SqlSugar 沟通中
3 222
该叫什么 lang 发布于2025/1/2
悬赏:0 飞吻

多对多导航插入,在中间表中增加自定义参数 导航插入要怎么查询,数据结构如下

//实体

public class ABMapping1

{

    [SugarColumn(IsPrimaryKey = true)]//中间表可以不是主键

    public int AId { get; set; }

    [SugarColumn(IsPrimaryKey = true)]//中间表可以不是主键

    public int BId { get; set; }

public string AName { get; set; }

}

public class A1

{

    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]

    public int Id { get; set; }

    public string Name { get; set; }

    [Navigate(typeof(ABMapping1), nameof(ABMapping1.AId), nameof(ABMapping1.BId))]//注意顺序

    public List<B1> BList { get; set; }//只能是null不能赋默认值

}

public class B1

{

    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]

    public int Id { get; set; }

    public string Name { get; set; }

    [Navigate(typeof(ABMapping1), nameof(ABMapping1.BId), nameof(ABMapping1.AId))]//注意顺序

    public List<A1> AList { get; set; }//只能是null不能赋默认值


热忱回答3

  • lang lang VIP0
    2025/1/2

    中间表中的AName 是新增字段

    0 回复
  • 只能直接查中间表


    0 回复
  • lang lang VIP0
    2025/1/3

    数据插入呢,先导航插入,再查中间表给AName赋值,目前我想到的就这一种方式。还有其它方式吗

    0 回复