Skip to content
Snippets Groups Projects
Commit 361e7df3 authored by esantangelo's avatar esantangelo
Browse files

commit

parent a49bb6d4
No related branches found
No related tags found
1 merge request!5Multi tenancy
......@@ -17,6 +17,10 @@ namespace Tsi1.DataLayer.Entities
public int CourseId { get; set; }
public int TenantId { get; set; }
public Tenant Tenant { get; set; }
public Course Course { get; set; }
public ICollection<Post> Posts { get; set; }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.DataLayer.Entities
{
public class Tenant
{
public Tenant()
{
Forums = new HashSet<Forum>();
}
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Forum> Forums { get; set; }
}
}
......@@ -25,6 +25,10 @@ namespace Tsi1.DataLayer.EntityConfiguration
.WithMany(x => x.Forums)
.HasForeignKey(x => x.CourseId);
builder.HasOne(x => x.Tenant)
.WithMany(x => x.Forums)
.HasForeignKey(x => x.TenantId);
}
}
}
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Text;
using Tsi1.DataLayer.Entities;
namespace Tsi1.DataLayer.EntityConfiguration
{
class TenantConfiguration : IEntityTypeConfiguration<Tenant>
{
public void Configure(EntityTypeBuilder<Tenant> builder)
{
builder.HasKey(x => x.Id);
builder.HasIndex(x => x.Name)
.IsUnique();
builder.Property(x => x.Name)
.IsRequired()
.HasColumnType("character varying(50)");
}
}
}
......@@ -19,6 +19,7 @@ namespace Tsi1.DataLayer
public DbSet<Forum> Forums { get; set; }
public DbSet<Post> Posts { get; set; }
public DbSet<PostMessage> PostMessages { get; set; }
public DbSet<Tenant> Tenants { get; set; }
public Tsi1Context(DbContextOptions options) : base(options) { }
......@@ -35,6 +36,7 @@ namespace Tsi1.DataLayer
modelBuilder.ApplyConfiguration(new ForumConfiguration());
modelBuilder.ApplyConfiguration(new PostConfiguration());
modelBuilder.ApplyConfiguration(new PostMessageConfiguration());
modelBuilder.ApplyConfiguration(new TenantConfiguration());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment