πŸ“„ ContractTypeDetails Domain Model Documentation


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Data Model & Schema Mapping
  4. Class Properties Explained
  5. EF Core Configuration
  6. UML Class Diagram
  7. Usage Examples & Code Snippets
  8. Best Practices & Tips
  9. Conclusion

1. Overview & Purpose

The ContractTypeDetails class is a Domain Model within the IrbyImaging.DomainClasses namespace. It represents the structure of the ContractTypeDetails table in your database, capturing a summary of contracts by state and work type. This class is intended for:

  • πŸ“Š Data storage: Persisting contract statistics (counts) per state and work category.
  • πŸ”„ Entity Framework Core mapping: Leveraging EF Core for CRUD operations.
  • 🀝 Business logic integration: Serving as a data carrier in repository or service layers.

2. Dependencies & Technologies

Technology / Package Purpose
.NET Core / .NET 5+ Runtime for the application.
Microsoft.EntityFrameworkCore ORM for mapping C# classes to database tables.
System.ComponentModel.DataAnnotations Provides attribute-based validation and schema mapping (e.g., [Key], [Table]).

3. Data Model & Schema Mapping

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

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

        public string State { get; set; }

        public string TypeOfWork { get; set; }

        public int NumberOfContracts { get; set; }
    }
}
  • [Table] attribute
    • Maps this class to the irby.ContractTypeDetails table.
  • [Key] attribute
    • Marks Id as the primary key column.

4. Class Properties Explained

Property Type Nullable Description
Id Guid No Unique identifier for each record. Primary key.
State string Yes U.S. state (e.g., "NY", "CA").
TypeOfWork string Yes Category or type of the contract/work performed.
NumberOfContracts int No Total count of contracts matching the state & type.

ℹ️ Note: By default, strings are mapped to nullable columns in EF Core. Adjust via Fluent API or [Required] if you need non-nullable strings.


5. EF Core Configuration

No extra Fluent API configuration is required beyond the data‑annotation attributes. However, you can further customize in your DbContext:

public class IrbyContext : DbContext
{
    public DbSet<ContractTypeDetails> ContractTypeDetails { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ContractTypeDetails>(entity =>
        {
            entity.HasKey(e => e.Id);
            entity.Property(e => e.State).HasMaxLength(2);
            entity.Property(e => e.TypeOfWork).HasMaxLength(100);
        });
    }
}
  • HasMaxLength: Enforces column length in the database.
  • HasKey: Explicit primary key declaration (redundant if [Key] is used).

6. UML Class Diagram

classDiagram
    IrbyImaging.DomainClasses.ContractTypeDetails {
        +Guid Id
        +string State
        +string TypeOfWork
        +int NumberOfContracts
    }

7. Usage Examples & Code Snippets

7.1. Inserting a New Record

using (var context = new IrbyContext())
{
    var detail = new ContractTypeDetails
    {
        Id = Guid.NewGuid(),
        State = "TX",
        TypeOfWork = "Electrical",
        NumberOfContracts = 42
    };

    context.ContractTypeDetails.Add(detail);
    context.SaveChanges();
}

7.2. Fetching & Querying

// Get all Texas electrical contracts
var texasElectrical = await context.ContractTypeDetails
    .Where(d => d.State == "TX" && d.TypeOfWork == "Electrical")
    .ToListAsync();

7.3. Updating a Record

var record = context.ContractTypeDetails.First(d => d.Id == existingId);
record.NumberOfContracts += 1;
context.SaveChanges();

7.4. Deleting a Record

var toDelete = context.ContractTypeDetails.Find(existingId);
context.ContractTypeDetails.Remove(toDelete);
context.SaveChanges();

8. Best Practices & Tips

  • πŸ›  Validation: Use [Required], [MaxLength], or Fluent API to enforce data integrity.
  • πŸ”„ Concurrency: Consider adding a RowVersion (byte[]) for optimistic concurrency control.
  • πŸ“¦ Batch Operations: For bulk insert/update, look into EF Core’s BulkExtensions or raw SQL for performance.
  • βš™οΈ Migration: After changing the model, run Add-Migration & Update-Database.

9. Conclusion

The ContractTypeDetails class is a simple yet essential building block in the Irby Imaging domain, capturing critical contract statistics across states and work types. By combining EF Core attributes and best practices, you can efficiently persist and query this data, integrating it seamlessly into your business logic layers.

Happy coding! πŸ™Œ


Generated by the Irby Imaging Documentation Generator πŸš€