In multi tenant application, we can force the ID that is in another tenant in dropdown for example
My models is:
public class Tenant
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Customer
{
public int Id { get; set; }
public int TenantId { get; set; }
public string Name { get; set;}
}
public class Order
{
public int Id { get; set; }
public int CustomerId { get; set; }
public int TenantId { get; set; }
public float Price { get; set; }
}
this code should generate a table similar to this:
CREATE TABLE tenant (
id INT NOT NULL,
nome VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE customer (
id INT NOT NULL,
id_tenant INT NOT NULL,
nome VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (id_tenant) REFERENCES tenant(id),
-- pra ter a FK composta, tem que ter chave composta na tabela de origem
UNIQUE (Id,id_tenant)
);
CREATE TABLE [order] (
id INT NOT NULL,
id_customer INT NOT NULL,
id_tenant INT NOT NULL,
nome VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (id_customer, id_tenant) REFERENCES customer (id, id_tenant),
FOREIGN KEY (id_tenant) REFERENCES tenant(id)
);
But, how create composite using FLUENT API?
EDIT: I want to ensure that the CustomerID passed to the Order.cs has the same TenantId
That is, Customer and Order must have the same TenantId