πŸ“’ IrbyImaging.DomainClasses/Customer.cs Documentation


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Model
  5. Entity Framework Mapping
  6. UML Class Diagram
  7. Usage Examples
  8. Best Practices & Notes
  9. Conclusion

🧐 Overview & Purpose

The Customer class is a domain entity within the IrbyImaging.DomainClasses assembly.
It represents a customer record in the Irby Imaging application and is mapped to a relational database via Entity Framework Core.

Primary responsibilities:

  • Store unique customer identifiers.
  • Record customer-specific metadata (e.g., number, name).
  • Facilitate CRUD operations against the irby.Customer table.

πŸ›  Dependencies & Technologies

Technology / Namespace Purpose
System Core .NET base types (e.g., Guid).
System.Collections.Generic Collection interfaces (commented-out navigation property).
System.ComponentModel.DataAnnotations Data validation and display attributes.
System.ComponentModel.DataAnnotations.Schema Table and schema mapping attributes.
Entity Framework Core ORM for mapping domain classes to database tables.

πŸ”‘ Key Functional Areas

  • Entity Definition
    Defines the Customer entity and associates it with a database table.
  • Data Annotations
    Applies [Key], [Table], and [Display] attributes for schema and UI metadata.
  • Navigation Stubs
    (Commented out) potential relationships to other entities like Employee.

πŸ—ƒ Data Model

Class Definition

namespace IrbyImaging.DomainClasses
{
    /// <summary>
    /// Represents a Customer in the Irby Imaging system.
    /// </summary>
    [Table("Customer", Schema = "irby")]
    public class Customer
    {
        [Key]
        public Guid Id { get; set; }

        [Display(Name = "Customer Number")]
        public string CustomerNumber { get; set; }

        public string Name { get; set; }

        // public ICollection<Employee> Employees { get; set; }
    }
}
  • Schema: irby
  • Table: Customer

Property Details

Property Type Annotations Description
Id Guid [Key] Primary key, unique identifier.
CustomerNumber string [Display(Name = "Customer Number")] Business-facing customer code.
Name string β€” Full customer name.
Employees β€” (Commented-out) Navigation to related Employee entities.

πŸ—Ί Entity Framework Mapping

  1. Table Mapping

    [Table("Customer", Schema = "irby")]
    
    • Maps the class to irby.Customer in the database.
  2. Primary Key

    [Key]
    public Guid Id { get; set; }
    
    • Denotes Id as the table’s primary key.
  3. Display Metadata

    [Display(Name = "Customer Number")]
    public string CustomerNumber { get; set; }
    
    • Provides UI-friendly label for form scaffolding.

πŸ“ UML Class Diagram

classDiagram
    class Customer {
        <<Entity>>
        +Guid Id
        +string CustomerNumber
        +string Name
        // +ICollection~Employee~ Employees
    }
    %% Relationship (commented out)
    %% Customer "1" o-- "*" Employee

πŸ’» Usage Examples

Creating and Saving a Customer

using (var context = new IrbyImagingContext())
{
    var newCustomer = new Customer
    {
        Id = Guid.NewGuid(),
        CustomerNumber = "CUST-2022-0001",
        Name = "Contoso Imaging"
    };

    context.Customers.Add(newCustomer);
    context.SaveChanges();
    Console.WriteLine($"Customer '{newCustomer.Name}' created with ID {newCustomer.Id}");
}

Querying Customers

using (var context = new IrbyImagingContext())
{
    var existing = context.Customers
                          .Where(c => c.CustomerNumber.StartsWith("CUST-2022"))
                          .OrderBy(c => c.Name)
                          .ToList();

    foreach (var cust in existing)
    {
        Console.WriteLine($"{cust.CustomerNumber}: {cust.Name}");
    }
}

πŸ“ Best Practices & Notes

  • πŸ’‘ GUID Generation
    Always assign Id = Guid.NewGuid() before saving to ensure uniqueness.
  • πŸ“‹ Schema Consistency
    Verify the irby schema exists in your database or adjust in your DbContext.
  • ⚠️ Commented Code
    The Employees navigation property is currently commented outβ€”uncomment and define Employee if relations are needed.
  • πŸ›  Migrations
    Run Add-Migration InitCustomer β†’ Update-Database to apply to your database.

🎯 Conclusion

The Customer class is a simple yet pivotal domain model that captures basic customer information for Irby Imaging.
By leveraging Entity Framework’s data annotations and a clear domain model, you can quickly scaffold, query, and maintain customer records in your application.

Feel free to extend this class with additional properties or relationships (e.g., ICollection<Order> or ICollection<Employee>) to fit your business requirements. πŸš€