【发布时间】:2018-12-23 02:24:59
【问题描述】:
假设您有一个租户,该租户有许多用户,这些用户有许多帐户,有许多交易。
您将 TenantId 属性添加到树的多远?
您添加 UserId 的树有多远?
还是您只需要拥有父 ID?
假设用户在没有首先访问其父实体的情况下永远不会有意访问子实体。在一个蛞蝓中,它会是这样的:
baseurl.com/accounts/{accountId/transactions/{transactionId}
public class Tenant
{
public long Id { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Users { get; set; }
public virtual ICollection<Account> Accounts { get; set; }
public virtual ICollection<Transaction> Transactions { get; set; }
}
public class User
{
public long Id { get; set; }
public long TenantId { get; set; }
public string Name { get; set; }
public virtual ICollection<Account> Accounts { get; set; }
}
public class Account
{
public long Id { get; set; }
public long TenantId { get; set; }
public string UserId { get; set; }
public virtual ICollection<Transaction> Transactions { get; set; }
}
public class Transaction
{
public long Id { get; set; }
public long TenantId { get; set; }
public string UserId { get; set; }
public string AccountId { get; set; }
}
我倾向于看到在属于租户的所有内容上使用 TenantId 的示例。我想这是为了安全,但我的自然假设是 UserId 就足够了。例如,即使 Transaction 比 User 低两个级别,我认为我不应该允许任何知道 Transaction ID 的人访问交易而不是拥有该帐户的用户。
【问题讨论】:
标签: c# .net multi-tenant hierarchical-data