Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1对1模式下,如果两个实体类的主键都设置了Id自增,会在保存的时候抛出异常 提示Id有值。 #1765

Open
yangf85 opened this issue Mar 31, 2024 · 1 comment

Comments

@yangf85
Copy link

yangf85 commented Mar 31, 2024

要怎么处理?

问题描述及重现代码:

// c# code
 public class PersonEntity
 {
     [Column(IsPrimary = true, IsIdentity = true)]
     public int Id { get; set; }

     [Column(Position = 4)]
     public int Age { get; set; } = Random.Shared.Next(1, 36);

     [Column(Position = 3)]
     public Gender Gender { get; set; }

     [Column(Position = 2)]
     public string Name { get; set; }

     [Navigate(nameof(Id))]
     public OrderEntity Order { get; set; }
 }
public class OrderEntity
{
    [Column(IsPrimary = true, IsIdentity = true)]
    public int Id { get; set; }

    public string Number { get; set; }

    [Navigate(nameof(Id))]
    public PersonEntity Person { get; set; }

    [Navigate(nameof(Id))]
    public SummaryEntity Summary { get; set; }

    [Navigate(nameof(PartEntity.OrderId))]
    public List<PartEntity> Parts { get; set; }

    public string Notes { get; set; }
}

数据库版本

安装的Nuget包

.net framework/. net core? 及具体版本

image

@2881099
Copy link
Collaborator

2881099 commented Apr 1, 2024

一对一,怎么会两边同时自增。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants