📋 Documentation: DirectorProperties.cs


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Data Model: DirectorProperties
  4. Entity Framework Core Mapping
  5. Usage Examples
  6. Sample Code Snippets
  7. UML Class Diagram
  8. Conclusion

1. Overview & Purpose 🎯

The DirectorProperties class resides in the IrbyImaging.DomainClasses namespace and represents a single row in the irby.DirectorProperties database table. Each instance tracks:

  • Which director (by name)
  • Which U.S. state
  • How many properties that director oversees in that state

This entity is designed for use with Entity Framework Core (EF Core) as part of the Irby Imaging data access layer.


2. Dependencies & Technologies ⚙️

Category Detail
Language C#
.NET Version .NET Core / .NET 5+
ORM Entity Framework Core (EF Core)
Data Annotations System.ComponentModel.DataAnnotations
Schema Mapping System.ComponentModel.DataAnnotations.Schema

Key NuGet Packages:

  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Relational

3. Data Model: DirectorProperties 🔍

namespace IrbyImaging.DomainClasses
{
    [Table("DirectorProperties", Schema = "irby")]
    public class DirectorProperties
    {
        [Key]
        public Guid Id { get; set; }

        public string State { get; set; }

        public string Director { get; set; }

        public int NumberOfProperties { get; set; }
    }
}

Property Breakdown

Property Type Description
Id Guid Primary Key – unique record identifier
State string Two‐letter U.S. state code (e.g. “CA”, “NY”)
Director string Name of the director (e.g. “Jane Doe”)
NumberOfProperties int Count of properties under that director/state

Note: Consider adding [Required] attributes if null values should be disallowed.


4. Entity Framework Core Mapping 🔧

EF Core will automatically map this class to the irby.DirectorProperties table using Data Annotations:

  • [Table("DirectorProperties", Schema = "irby")]
  • [Key] marks the Id property as the primary key.

DbContext Configuration Example

public class IrbyDbContext : DbContext
{
    public DbSet<DirectorProperties> DirectorProperties { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseSqlServer("YourConnectionStringHere");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Fluent API alternative to annotations (optional)
        modelBuilder.Entity<DirectorProperties>()
            .ToTable("DirectorProperties", "irby")
            .HasKey(dp => dp.Id);
    }
}

5. Usage Examples 📚

5.1 Adding a New Record

using var context = new IrbyDbContext();
var newRecord = new DirectorProperties
{
    Id = Guid.NewGuid(),
    State = "TX",
    Director = "Alice Smith",
    NumberOfProperties = 27
};

context.DirectorProperties.Add(newRecord);
await context.SaveChangesAsync();

5.2 Querying Records by State

using var context = new IrbyDbContext();
var texasDirectors = await context.DirectorProperties
    .Where(dp => dp.State == "TX")
    .OrderByDescending(dp => dp.NumberOfProperties)
    .ToListAsync();

foreach (var dp in texasDirectors)
{
    Console.WriteLine($"{dp.Director} manages {dp.NumberOfProperties} properties in {dp.State}");
}

5.3 Updating an Existing Record

var record = await context.DirectorProperties.FindAsync(existingId);
if (record != null)
{
    record.NumberOfProperties += 5;
    await context.SaveChangesAsync();
}

6. Sample Code Snippets 📑

LINQ Grouping Example

Group directors by state and compute totals:

var summary = await context.DirectorProperties
    .GroupBy(dp => dp.State)
    .Select(g => new {
        State = g.Key,
        TotalProperties = g.Sum(x => x.NumberOfProperties)
    })
    .ToListAsync();

Deletion Example

var toDelete = await context.DirectorProperties
    .FirstOrDefaultAsync(dp => dp.Director == "Bob Johnson");
if (toDelete != null)
{
    context.DirectorProperties.Remove(toDelete);
    await context.SaveChangesAsync();
}

7. UML Class Diagram 🔎

classDiagram
    class DirectorProperties {
        +Guid Id
        +string State
        +string Director
        +int NumberOfProperties
    }

8. Conclusion ✅

The DirectorProperties domain class is a simple, EF Core‐ready entity encapsulating the relationship between directors, their geographic region, and the count of properties they oversee. Use it to store, query, and manipulate director/property statistics within the irby schema. Its clear structure and annotation‐based mapping make it straightforward to integrate into any data access layer powered by Entity Framework Core.

Feel free to extend this class with validation attributes (e.g., [Required], [MaxLength]) or navigation properties if you need to relate directors or properties to other entities in your domain.