Skip to content

Instantly share code, notes, and snippets.

@HarshaSuranjith
Last active October 10, 2023 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarshaSuranjith/1fc25737cbaf1431edb13faef4a9d590 to your computer and use it in GitHub Desktop.
Save HarshaSuranjith/1fc25737cbaf1431edb13faef4a9d590 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;

namespace YourNamespace.Domain.Entities
{
    public class Organization
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public ICollection<Employee> Employees { get; set; } = new List<Employee>();
    }

    public class Employee
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Designation { get; set; }
        public Guid OrganizationId { get; set; }
        public Organization Organization { get; set; }
        public ICollection<BoardResolutionSignatory> SignedResolutions { get; set; } = new List<BoardResolutionSignatory>();
    }

    public class BoardResolution
    {
        public Guid Id { get; set; }
        public string Description { get; set; }
        public DateTime DatePassed { get; set; }
        public ICollection<BoardResolutionSignatory> BoardResolutionSignatories { get; set; } = new List<BoardResolutionSignatory>();
    }

    public class BoardResolutionSignatory
    {
        public Guid EmployeeId { get; set; }
        public Employee Employee { get; set; }
        public Guid BoardResolutionId { get; set; }
        public BoardResolution BoardResolution { get; set; }
    }
}



#######################3

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

public class OrganizationConfiguration : IEntityTypeConfiguration<Organization>
{
    public void Configure(EntityTypeBuilder<Organization> builder)
    {
        builder.ToTable("xt_organizations");
        builder.HasKey(o => o.Id);
        builder.HasMany(o => o.Employees)
            .WithOne(e => e.Organization)
            .HasForeignKey(e => e.OrganizationId);
    }
}

public class EmployeeConfiguration : IEntityTypeConfiguration<Employee>
{
    public void Configure(EntityTypeBuilder<Employee> builder)
    {
        builder.ToTable("xt_employees");
        builder.HasKey(e => e.Id);
    }
}

public class BoardResolutionConfiguration : IEntityTypeConfiguration<BoardResolution>
{
    public void Configure(EntityTypeBuilder<BoardResolution> builder)
    {
        builder.ToTable("xt_board_resolutions");
        builder.HasKey(b => b.Id);
        builder.HasMany(b => b.BoardResolutionSignatories)
            .WithOne(s => s.BoardResolution)
            .HasForeignKey(s => s.BoardResolutionId);
    }
}

public class BoardResolutionSignatoryConfiguration : IEntityTypeConfiguration<BoardResolutionSignatory>
{
    public void Configure(EntityTypeBuilder<BoardResolutionSignatory> builder)
    {
        builder.ToTable("xt_board_resolution_signatories");
        builder.HasKey(s => new { s.EmployeeId, s.BoardResolutionId });

        builder.HasOne(s => s.Employee)
            .WithMany(e => e.SignedResolutions)
            .HasForeignKey(s => s.EmployeeId);

        builder.HasOne(s => s.BoardResolution)
            .WithMany(b => b.BoardResolutionSignatories)
            .HasForeignKey(s => s.BoardResolutionId);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment