为租户(Tenants)生成代码

启动 Sergen ,并使用 Default 连接为 租户(Tenants)表生成代码。

Tenants Table

然后,我们在 TenantRow 定义检索脚本,并把 InstanceName 属性设置为 Tenant

  1. namespace MultiTenancy.Administration.Entities
  2. {
  3. //...
  4. [ConnectionKey("Default"), DisplayName("Tenants"),
  5. InstanceName("Tenant"), TwoLevelCached]
  6. [LookupScript("Administration.Tenant")]
  7. public sealed class TenantRow : Row, IIdRow, INameRow
  8. {
  9. [DisplayName("Tenant Id"), Identity]
  10. public Int32? TenantId
  11. {
  12. get { return Fields.TenantId[this]; }
  13. set { Fields.TenantId[this] = value; }
  14. }
  15. //...

让我们定义一个只有 admin 用户有的 Administration:Tenants 权限:

  1. namespace MultiTenancy.Administration
  2. {
  3. public class PermissionKeys
  4. {
  5. public const string Security = "Administration:Security";
  6. public const string Translation = "Administration:Translation";
  7. public const string Tenants = "Administration:Tenants";
  8. }
  9. }

并把它设置到 TenantRow:

  1. [ConnectionKey("Default"), DisplayName("Tenants"), InstanceName("Tenant"), TwoLevelCached]
  2. [ReadPermission(PermissionKeys.Tenants)]
  3. [ModifyPermission(PermissionKeys.Tenants)]
  4. [LookupScript("Administration.Tenant")]
  5. public sealed class TenantRow : Row, IIdRow, INameRow
  6. {