/// <summary> /// This method configures the database model with EF Core's fluent API /// </summary> protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); string tenantId = "TenantId"; // Measurement Units AddTenantId <MeasurementUnit>(builder); MeasurementUnit.OnModelCreating(builder); // Custodies AddTenantId <Custody>(builder); Custody.OnModelCreating(builder); // Agents : Custodies Agent.OnModelCreating_Agent(builder); // Roles AddTenantId <Role>(builder); Role.OnModelCreating(builder); // Views AddTenantId <View>(builder); View.OnModelCreating(builder); // Local Users AddTenantId <LocalUser>(builder); LocalUser.OnModelCreating(builder); // Role Memberships AddTenantId <RoleMembership>(builder); RoleMembership.OnModelCreating(builder); // Permissions AddTenantId <Permission>(builder); Permission.OnModelCreating(builder); // Settings AddTenantId <Settings>(builder, tenantId); Data.Model.Settings.OnModelCreating(builder); // Blobs AddTenantId <Blob>(builder, nameof(Blob.Id), tenantId); Blob.OnModelCreating(builder); // EF migratios was confused about these for some reason, had to set them manually builder.Entity <Dto.AgentForQuery>().HasOne(e => e.CreatedBy).WithMany().HasForeignKey(e => e.CreatedById); builder.Entity <Dto.AgentForQuery>().HasOne(e => e.ModifiedBy).WithMany().HasForeignKey(e => e.ModifiedById); builder.Entity <Dto.LocalUserForQuery>().HasOne(e => e.Agent).WithMany().HasForeignKey(e => e.AgentId); builder.Entity <Dto.RoleMembershipForQuery>().HasOne(e => e.User).WithMany(e => e.Roles).HasForeignKey(e => e.UserId); builder.Entity <Dto.RoleMembershipForQuery>().HasOne(e => e.CreatedBy).WithMany().HasForeignKey(e => e.CreatedById); builder.Entity <Dto.RoleMembershipForQuery>().HasOne(e => e.ModifiedBy).WithMany().HasForeignKey(e => e.ModifiedById); }
/// <summary> /// This method configures the database model with EF Core's fluent API /// </summary> protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); string tenantId = "TenantId"; // Measurement Units AddTenantId <MeasurementUnit>(builder); MeasurementUnit.OnModelCreating(builder); // Custodies AddTenantId <Custody>(builder); Custody.OnModelCreating(builder); // Agents : Custodies Agent.OnModelCreating_Agent(builder); // Roles AddTenantId <Role>(builder); Role.OnModelCreating(builder); // Views AddTenantId <View>(builder); View.OnModelCreating(builder); // Local Users AddTenantId <LocalUser>(builder); LocalUser.OnModelCreating(builder); // Role Memberships AddTenantId <RoleMembership>(builder); RoleMembership.OnModelCreating(builder); // Permissions AddTenantId <Permission>(builder); Permission.OnModelCreating(builder); // Settings AddTenantId <Settings>(builder, tenantId); Data.Model.Settings.OnModelCreating(builder); // Blobs AddTenantId <Blob>(builder, nameof(Blob.Id), tenantId); Blob.OnModelCreating(builder); }