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

Foreign key error #782

Open
aydinbskr opened this issue Sep 23, 2022 · 1 comment
Open

Foreign key error #782

aydinbskr opened this issue Sep 23, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@aydinbskr
Copy link

At some tables, the system not add inner join

@Mike6x
Copy link

Mike6x commented Dec 23, 2022

Same issue:

I have class as belowing.

  • When I create a employee with DepartmentId & SubDepartmentId != null => Sucessfully !
  • When I create a employee with DepartmentId != null & SubDepartmentId = null => Failed with error:

(0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Employees_SubDepartments_SubDepartmentId".
The conflict occurred in database "rootTenantDb", table "SubDepartments", column 'Id'.

How to fix or work around it ???

public class Employee : AuditableEntity, IAggregateRoot
{
public string FirstName { get; private set; }
public string? LastName { get; private set;
.....
public DefaultIdType DepartmentId { get; private set; }
public virtual Department Department { get; private set; } = default!;

public DefaultIdType? SubDepartmentId { get; private set; }
public virtual SubDepartment SubDepartment { get; private set; } = default!;
}

public class SubDepartment : AuditableEntity, IAggregateRoot
{
public string Name { get; private set; } = default!;
public string Description { get; private set; } = string.Empty;

public DefaultIdType DepartmentId { get; private set; }
public virtual Department Department { get; private set; } = default!;
}

public class Department : AuditableEntity, IAggregateRoot
{

public string Name { get; private set; } = default!;
public string Description { get; private set; } = string.Empty;
}

@iammukeshm iammukeshm added the bug Something isn't working label Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants