📄 Documentation: ContractsByLead.cs
Welcome to the detailed documentation for the ContractsByLead entity located in the IrbyImaging.DomainClasses namespace. This document covers everything from the overall purpose to sample usage, EF Core integration, and a UML class diagram.
📑 Table of Contents
- Overview & Purpose
- Key Functional Areas
- Schema Configuration & EF Core Mapping
- Properties & Data Annotations
- Dependencies & Technologies
- Usage & Code Snippets
- Class Diagram (UML)
- Conclusion
1. Overview & Purpose 🚀
The ContractsByLead class is a domain model representing an aggregation of contracts grouped by a lead director. It is designed for:
- Reporting: Easily fetch how many contracts each director leads.
- Analytics: Drive dashboards, charts, or data exports.
- Simplicity: A minimal entity with the requisite fields needed for “contracts by lead” queries.
This entity is mapped to the irby.ContractsByLead table in a relational database via Entity Framework Core.
2. Key Functional Areas 🛠️
- Data Storage
Stores the count of contracts per director. - ORM Mapping
Uses EF Core’s[Table],[Key], and other Data Annotations to map C# properties to database columns. - Reporting & Queries
Acts as the target shape for LINQ queries or stored procedures that return contract counts by director.
3. Schema Configuration & EF Core Mapping ⚙️
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace IrbyImaging.DomainClasses
{
[Table("ContractsByLead", Schema = "irby")]
public class ContractsByLead
{
[Key]
public Guid Id { get; set; }
public string Director { get; set; }
public int NumberOfContracts { get; set; }
}
}
- [Table("ContractsByLead", Schema = "irby")]
Maps this class to the tableirby.ContractsByLead. - [Key]
MarksIdas the primary key in the table.
4. Properties & Data Annotations 📋
| Property | Type | Attributes | Description |
|---|---|---|---|
| Id | Guid | [Key] | Unique identifier for the record. |
| Director | string | — | Name of the director leading the contracts. |
| NumberOfContracts | int | — | Total number of contracts for the director. |
Notes:
Idis assigned by the application (client-side) or by the database (server-side) depending on your configuration.Directorshould be non-nullable in practice; consider adding[Required]if your database allows nulls by default.
5. Dependencies & Technologies 📦
- .NET 6+ / .NET Core
- Entity Framework Core (Microsoft.EntityFrameworkCore)
- System.ComponentModel.DataAnnotations
- System.ComponentModel.DataAnnotations.Schema
No external third‑party integrations are required beyond EF Core.
6. Usage & Code Snippets 📈
Below are examples showing how to integrate and work with ContractsByLead in your application.
6.1 Adding to Your DbContext
using Microsoft.EntityFrameworkCore;
using IrbyImaging.DomainClasses;
public class ImagingDbContext : DbContext
{
public DbSet<ContractsByLead> ContractsByLeads { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Example: Use SQL Server
optionsBuilder.UseSqlServer("Your_Connection_String");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Fluent API is optional since DataAnnotations are used.
modelBuilder.Entity<ContractsByLead>()
.ToTable("ContractsByLead", schema: "irby");
}
}
6.2 CRUD Operations Examples
Create (Add a New Record)
using var db = new ImagingDbContext();
var newEntry = new ContractsByLead
{
Id = Guid.NewGuid(),
Director = "Jane Doe",
NumberOfContracts = 15
};
db.ContractsByLeads.Add(newEntry);
db.SaveChanges();
Read (Query By Director)
var janeStats = db.ContractsByLeads
.FirstOrDefault(c => c.Director == "Jane Doe");
Console.WriteLine($"{janeStats.Director} → {janeStats.NumberOfContracts} contracts");
Update (Modify Contracts Count)
var entry = db.ContractsByLeads.First(c => c.Director == "Jane Doe");
entry.NumberOfContracts += 5;
db.SaveChanges();
Delete (Remove a Record)
var toDelete = db.ContractsByLeads
.First(c => c.Director == "Jane Doe");
db.ContractsByLeads.Remove(toDelete);
db.SaveChanges();
7. Class Diagram (UML) 🧩
classDiagram
class ContractsByLead {
<<Entity>>
+Guid Id
+string Director
+int NumberOfContracts
}
8. Conclusion 🏁
The ContractsByLead class provides a lightweight, EF Core–mapped entity for tracking and analyzing the number of contracts led by each director. By leveraging Data Annotations and EF Core’s DbContext, you can easily integrate this entity into reporting modules, dashboards, or any data-driven component of your Irby Imaging solution.
Happy coding! 🎉