📄 Documentation: JobAndFieldOfficeMapping.cs


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Model
    4.1. Entity Configuration
    4.2. Properties & Details
  5. UML Class Diagram
  6. Helper Methods & Utilities
  7. Error Handling & Return Types
  8. API Endpoints Overview
  9. Third‑Party Integrations
  10. Sample Code Blocks
  11. Usage Examples
  12. Conclusion

1. Overview & Purpose

The JobAndFieldOfficeMapping class is a keyless EF Core entity designed to represent a flattened view of Jobs combined with their corresponding Field Office details. This class is commonly used for:

  • 📊 Reporting and analytics
  • 📍 Geospatial queries (latitude/longitude)
  • 🏢 Aggregate dashboards (job counts, employee counts, etc.)

Key point:
Because it's marked with [Keyless], it's ideal for mapping database views or raw SQL queries that don’t expose a single primary key.


2. Dependencies & Technologies

Component Purpose
Microsoft.EntityFrameworkCore [Keyless] attribute, Fluent API mapping
.NET (C#) Language/runtime
System, System.Collections.Generic, etc. Basic types & collections support

3. Key Functional Areas

  • 📍 Location Data
    • Latitude, Longitude for mapping jobs on a map.
  • 🏢 Office Information
    • Field office name, ID, mailing & shipping addresses.
  • 🏗 Job Metadata
    • Job number, name, address number.
  • 👤 Personnel
    • Manager, Project Manager, Superintendent, Lead.
  • 🔢 Metrics & Counts
    • JobCount, EmployeeCount, AssetsCount, EquipmentCount, POCount, WOCount.

4. Data Model

4.1. Entity Configuration

Since JobAndFieldOfficeMapping is a read‑only, keyless type, you’ll typically register it in your DbContext like so:

public class IrbyImagingContext : DbContext
{
    public DbSet<JobAndFieldOfficeMapping> JobFieldOfficeMappings { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder
            .Entity<JobAndFieldOfficeMapping>()
            .HasNoKey()                    // Marks the entity as keyless
            .ToView("vw_JobAndFieldOfficeMapping"); // Maps to a database view
    }
}

Tip:
Use .FromSqlRaw(...) or map to a SQL view for complex joins between Jobs and FieldOffices.

4.2. Properties & Details

Property Type Description
Latitude decimal 📍 Geographical latitude of the job/office
Longitude decimal 📍 Geographical longitude of the job/office
FieldOffice string 🏢 Name of the field office
FieldOfficeId Guid 🏢 Unique ID of the field office
MailingAddress string 🏠 Mailing address for correspondence
ShippingAddress string 📦 Physical shipping address
JobNumber string 🔢 Job identifier
JobName string 🏗 Descriptive name/title of the job
AddressNumber string 🔢 Street/Unit number portion of the job’s address
Manager string 👤 Job manager
ProjectManager string 👷 Project manager
Superintendent string 🛠 Job superintendent
Lead string 🏅 Team lead
JobCount string 🔢 Number of jobs in this office (string for display)
EmployeeCount string 👥 Number of employees
AssetsCount string 💼 Number of assets
EquipmentCount string 🚜 Number of equipment
POCount string 🧾 Number of purchase orders
WOCount string 📋 Number of work orders

Note:
Counts are represented as string to accommodate formatting or NULL handling in the underlying view.


5. UML Class Diagram

classDiagram
    class JobAndFieldOfficeMapping {
        <<Keyless Entity>>
        +decimal Latitude
        +decimal Longitude
        +string FieldOffice
        +Guid FieldOfficeId
        +string MailingAddress
        +string ShippingAddress
        +string JobNumber
        +string JobName
        +string AddressNumber
        +string Manager
        +string ProjectManager
        +string Superintendent
        +string Lead
        +string JobCount
        +string EmployeeCount
        +string AssetsCount
        +string EquipmentCount
        +string POCount
        +string WOCount
    }

6. Helper Methods & Utilities

None in this class.
All properties are auto-implemented; no behavior or custom logic is included here.


7. Error Handling & Return Types

  • Error Handling: N/A (POCO/DTO class)
  • Return Types: Primitive CLR types (decimal, string, Guid)

8. API Endpoints Overview

This file does not define any Web API endpoints.
It’s strictly a domain/data model used by EF Core to retrieve or project data.


9. Third‑Party Integrations

  • Microsoft.EntityFrameworkCore
    • Provides the [Keyless] attribute and the Fluent API for mapping.

10. Sample Code Blocks

10.1. Class Definition

using Microsoft.EntityFrameworkCore;
using System;

namespace IrbyImaging.DomainClasses
{
    [Keyless]
    public class JobAndFieldOfficeMapping
    {
        public decimal Latitude { get; set; }
        public decimal Longitude { get; set; }
        public string FieldOffice { get; set; }
        public Guid FieldOfficeId { get; set; }
        public string MailingAddress { get; set; }
        public string ShippingAddress { get; set; }
        public string JobNumber { get; set; }
        public string JobName { get; set; }
        public string AddressNumber { get; set; }
        public string Manager { get; set; }
        public string ProjectManager { get; set; }
        public string Superintendent { get; set; }
        public string Lead { get; set; }
        public string JobCount { get; set; }
        public string EmployeeCount { get; set; }
        public string AssetsCount { get; set; }
        public string EquipmentCount { get; set; }
        public string POCount { get; set; }
        public string WOCount { get; set; }
    }
}

10.2. DbContext Registration

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder
        .Entity<JobAndFieldOfficeMapping>()
        .HasNoKey()
        .ToView("vw_JobAndFieldOfficeMapping");
}

11. Usage Examples

11.1. Fetch All Mappings

using var context = new IrbyImagingContext();
var allMappings = await context
    .JobFieldOfficeMappings
    .ToListAsync();

Console.WriteLine($"Total records: {allMappings.Count}");

11.2. Filter by Field Office

string officeName = "Dallas";
var dallasJobs = await context
    .JobFieldOfficeMappings
    .Where(m => m.FieldOffice == officeName)
    .OrderBy(m => m.JobNumber)
    .ToListAsync();

dallasJobs.ForEach(job =>
    Console.WriteLine($"{job.JobNumber} – {job.JobName} @ {job.FieldOffice}")
);

12. Conclusion

The JobAndFieldOfficeMapping class is a simple yet powerful representation of combined job and field‑office data. By leveraging EF Core’s keyless entities, you can:

  • Seamlessly map to database views or complex SQL queries
  • Render rich dashboards with geolocation and aggregated metrics
  • Keep your domain layer lean—no primary key enforcement, no unnecessary logic

Use this mapping to drive reporting, BI tools, or ad‑hoc analytics without polluting your core entity models. Happy coding! 🚀