π IrbyImaging.DomainClasses/Customer.cs Documentation
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model
- Entity Framework Mapping
- UML Class Diagram
- Usage Examples
- Best Practices & Notes
- 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.Customertable.
π 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 theCustomerentity 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 likeEmployee.
π 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
-
Table Mapping
[Table("Customer", Schema = "irby")]- Maps the class to
irby.Customerin the database.
- Maps the class to
-
Primary Key
[Key] public Guid Id { get; set; }- Denotes
Idas the tableβs primary key.
- Denotes
-
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 assignId = Guid.NewGuid()before saving to ensure uniqueness. - π Schema Consistency
Verify theirbyschema exists in your database or adjust in your DbContext. - β οΈ Commented Code
TheEmployeesnavigation property is currently commented outβuncomment and defineEmployeeif relations are needed. - π Migrations
RunAdd-Migration InitCustomerβUpdate-Databaseto 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. π